4

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 ?

Shew
  • 1,557
  • 1
  • 21
  • 36

1 Answers1

5

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     
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252