I have two dataframes.
df1
:
Name Symbol ID
0 Jay N/A 372Y105
1 Ray N/A 4446100
2 Faye N/A 484MAA4
3 Maye N/A 504W308
4 Kay N/A 782L107
5 Trey FFF 782L111
df2
:
Name Symbol ID
0 Jay AAA 372Y105
1 Faye CCC 484MAA4
2 Kay EEE 782L107
If ID
matches between df1
and df2
, I want to replace the symbol
in df1
with the symbol
from df2
, so that the output looks like:
Name Symbol ID
0 Jay AAA 372Y105
1 Ray N/A 4446100
2 Faye CCC 484MAA4
3 Maye N/A 504W308
4 Kay EEE 782L107
5 Trey FFF 782L111
It sounds like I should first concatenate the two dataframes, and then drop duplicates somehow, e.g.,
df3 = pd.concat([df1, df2])
df3 = df3.drop_duplicates(subset='ID', keep='last')
But rather than only keep the first or last duplicate, I only want to remove the ones where symbol
= N/A
.