I have a pandas dataframe df, where one column has a string in it:
columnA
'PSX - Judge A::PSK-Ama'
'VSC - Jep::VSC-Da'
'VSO - Jep::VSO-Da'
...
And I have another dataframe, where I have the new strings:
old new
PSX PCC
VSO VVV
My desired outcome would be:
columnA
'PCC - Judge A::PCC-Ama'
'VSC - Jep::VSC-Da'
'VVV - Jep::VVV-Da'
...
My idea would be to write:
import re
df['columnA'] = df.replace('PSX', 'PCC', regex=True)
df['columnA'] = df.replace('VSO', 'VVV', regex=True)
for two replacements it is ok, but how to do it for severel replacements? Is there a smarter way to do it?
The dataframe you get here (thx to Daniel):
df = pd.DataFrame(data=['PSX - Judge A::PSK-Ama',
'VSC - Jep::VSC-Da',
'VSO - Jep::VSO-Da'], columns=['columnA'])
replace = pd.DataFrame(data=[['PSX', 'PCC'],
['VSO', 'VVV']], columns=['old', 'new'])