I have two dataframes
df1=
| name | Code |
|---|---|
| 1234567 | H74 |
df2=
| name | Code |
|---|---|
| 1234567 | J11 |
| 1234321 | J12 |
I want to change 'Code' of df2 to the value that is in 'Code' of df1 if 'name' in df2 matches 'name' in df1.
I have tried creating a dictionary of df1;
dict = df1.set_index('name').to_dict()['Code']
df2.replace(dict)
However that results in changing 'name' to 'Code' like:
| name | Code |
|---|---|
| H74 | J11 |
| 1234321 | J12 |
Any help in achieving the following would be greatly appreciated:
| name | Code |
|---|---|
| 1234567 | H74 |
| 1234321 | J12 |
Thanks in advance!