Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replacing parenthesis from pandas dataframe [duplicate]

I used the below code

input_table = input_table.replace(to_replace='(', value="")

to replace the parenthesis from the entire dataframe. But for my surprise, it is not working. What might be wrong ?

like image 816
Shew Avatar asked Oct 30 '25 09:10

Shew


1 Answers

Need regex=True for replace substrings with escape ( because special regex value:

input_table = input_table.replace(to_replace='\(', value="", regex=True)

Sample:

input_table = pd.DataFrame({
    'A': ['(a','a','a','a(dd'],
    'B': ['a','a(dd', 'ss(d','((']
})
print (input_table)
      A     B
0    (a     a
1     a  a(dd
2     a  ss(d
3  a(dd    ((

input_table = input_table.replace(to_replace='\(', value="", regex=True)
print (input_table)
     A    B
0    a    a
1    a  add
2    a  ssd
3  add     
like image 192
jezrael Avatar answered Nov 01 '25 14:11

jezrael