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
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
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