I get this data frame:
Item .................
0 Banana (From Spain)...
1 Chocolate ............
2 Apple (From USA) .....
............
And I want change all Item's names by removing the parenthesis, getting finally
Item .................
0 Banana ...............
1 Chocolate ............
2 Apple ................
............
I thought, I should use replace but there are too much data so I'm thinking in use something like
import re
for i in dataframe.index:
if bool(re.search('.*\(.*\).*', dataframe.iloc[i]["Item"])):
dataframe.ix[i,"Item"] = dataframe.iloc[i]["Item"].split(" (")[0]
But I'm not sure if is the most efficient way.
df.Item = df.Item.str.replace('\([^\)]*\)', '')