I'd like to remove all items within a list. I've tried the below code to iterate through all items in a list within the context of a pandas .apply(). However, the function remove(x) only seems to be going to the first item in remove_l. How can I make sure it goes through all items in remove_l?
I know I can just create separate if statements, which I've already done, but I'd like to implement using a for loop just in case the list gets longer.
remove_l = [r'[A-Za-z]+(?:\/)', r'Today, ', '-']
def remove(x):
for phrase in remove_l:
if re.search(phrase, x):
if phrase == '-':
new = x.replace(phrase, ' ')
else:
new = x[re.search(phrase, x).span()[1]:].strip()
return new
else:
return x
#check up on items
#60, 330, 347, 411, 647
#idx = nocountries_df[nocountries_df.Name.str.contains('\/')].Name.index
nocountries_df.Name.apply(lambda x: remove(x))