I try to eliminate brackets and unnecessary marks in the dataframe.
Here's what my data look like:
df["address"]
index address
0 (#)(△)Kaohsiung City
1 (△)New Taipei City
2 (O)Chiayi City
.
.
Currently I'm using this:
def reshape_address(addr):
if addr[0] == "(":
return addr.split(")", 1)[-1]
else:
return addr
def run_reshape_addr(text):
text["address"] = text["address"].apply(reshape_address)
text["address"] = text["address"].apply(reshape_address)
text["address"] = text["address"].apply(reshape_address)
#run three times in order to get rid of multiple brackets
run_reshape_addr(df)
Somehow I got the IndexError: string index out of range. However, a partial of data have been executed successfully after this run even the error message pops up.
How can I revise this? And why were some of the data still being executed under this circumstance? Thank you.