I have two dataframes df1
and df2
. I would like to get the pred_label
from df2
to get assigned to the corresponding bar_cd
in df1
. there are some duplicate bar_cd
like 1006040448
in df1. I would not like to lose them due to the merge operation. I tried left merge but ended up getting null values for pred_label
Both df1 and df2 have similar bar_cd
.
If I would like to assign the pred_label
to df1 which approach would be suitable. I would appreciate your advice. Is there a way to map pred_label
to bar_cd
in df1
I have referred to the article [Merge 101][1]. But it did not work for me.
df1:
bar_cd actual_label
0 1006036382 3.0
1 1006040448 3.0
2 1006040448 3.0
3 1006044789 3.0
4 1006044789 3.0
df2: (consider this as master file for mapping)
bar_cd actual_label pred_label
133494 1006036382 3.00 3.00
180288 1006040448 3.00 4.00
122732 1006044789 3.00 4.00
38225 1006808018 1.00 2.00
205799 1008874962 2.00 1.00
expected result:
bar_cd actual_label pred_lable
0 1006036382 3.0 3.0
1 1006040448 3.0 4.0
2 1006040448 3.0 4.0
3 1006044789 3.0 4.0
4 1006044789 3.0 4.0
... ... ...
[1]: https://stackoverflow.com/questions/53645882/pandas-merging-101