How to remove parentheses and all data within using Pandas/Python?

df['name'].str.replace(r"\(.*\)","")

You can’t run re functions directly on pandas objects. You have to loop them for each element inside the object. So Series.str.replace((r"\(.*\)", "") is just syntactic sugar for Series.apply(lambda x: re.sub(r"\(.*\)", "", x)).

Leave a Comment