-1

How do I remove whatever is inside the brackets?

Sample string:

cost
889990(+2.4%)

My code:

data['cost']=re.sub(('(\d+)'), '', data.cost)

What I'm trying to achieve:

cost
889990
ctwheels
  • 21,901
  • 9
  • 42
  • 77

1 Answers1

1

You need to escape the parentheses in your regex string:

import re

s = 'cost 889990(+2.4%)'

print(re.sub(r'\([^)]*\)', '', s))

Prints:

cost 889990
Andrej Kesely
  • 168,389
  • 15
  • 48
  • 91