I have two columns in a CSV File, let's reference them as 'Current' and 'New'.
I would like to replace all strings in df['Names'] that contain a value in 'Current' with the corresponding value in 'New'.
My current dataframe:
| Names |
|---|
| Joseph |
| Robert |
My current code:
df['Names'] = df['Names'].replace('Joseph', 'Joe')
df['Names'] = df['Names'].replace('Robert', 'Rob')
My expected result:
| Names |
|---|
| Joe |
| Rob |
However, the list of replacements is huge, so I need a different more efficient method to replace the values. I would need to use a CSV file rather than a dictionary to hold the values to replace. The CSV file 'replace.csv' is set out as follows:
| Current | New |
|---|---|
| Joseph | Joe |
| Robert | Rob |