Im trying to replace certain values in a pandas column (dataframe) using regex, but I want to apply the regex based on values in another column.
A basic example;
index col1 col2
1 yes foobar
2 yes foo
3 no foobar
Using the following;
df.loc[df['col1'] == 'yes', 'col2'].replace({r'(fo)o(?!bar)' :r'\1'}, inplace=True, regex=True)
I expected the following result;
index col1 col2
1 yes foobar
2 yes fo
3 no foobar
However it doesn't seem to be working? It doesn't throw any errors or a settingwithcopy
warning, it just does nothing. Is there an alternative way to do this?