Say I have this dataframe:
df = pd.DataFrame({'Col': ['DDJFHGBC', 'AWDGUYABC']})
And I want to replace everything ending with ABC with ABC and everything ending with BC (except the ABC-cases) with BC. The output would look like:
Col
0 BC
1 ABC
How can I achieve this using regular expressions? I've tried things like:
df.Col.str.replace(r'\w*BC\b', 'BC')
df.Col.str.replace(r'\w*ABC\b', 'ABC')
But obviously these two lines are conflicting and I would end up with just BC in whichever order I use them.
ABCwithABCand everything ending withBC(except theABC-cases) withBC.A?BC$or match\w*?(A?BC)\band replace with group 1 regex101.com/r/fMcfHI/1BCorABCwith"". How can I do that?