-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
  • 20,701
  • 7
  • 36
  • 71

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
  • 118,151
  • 13
  • 38
  • 75