I'm having a hard time updating a string value in a subset of Pandas data frame
In the field action, I am able to modify the action column using regular expressions with:
df['action'] = df.action.str.replace('([^a-z0-9\._]{2,})','')
However, if the string contains a specific word, I don't want to modify it, so I tried to only update a subset like this:
df[df['action'].str.contains('TIME')==False]['action'] = df[df['action'].str.contains('TIME')==False].action.str.replace('([^a-z0-9\._]{2,})','')
and also using .loc like:
df.loc('action',df.action.str.contains('TIME')==False) = df.loc('action',df.action.str.contains('TIME')==False).action.str.replace('([^a-z0-9\._]{2,})','')
but in both cases, nothing gets updated. Is there a better way to achieve this?