I have 2 dataframes df1 and df2. df2 is shorter than df1. I am trying to copy an element pred from df2 into df1 if pedestrian in df2 exists in df1. I have looked at many posts but can't find one that addresses my problem.
Using map returns me a NaN everywhere in pred.
d = df2.set_index('pedestrian')['pred'].to_dict()
df1['pred'] = df2['pred'].map(d)
The program doesn't stop running if I use replace.
d = df2.set_index('pedestrian')['pred'].to_dict()
df1.replace(d)
Below is df1, df2 and what I would like the output to be.
df1
pred true pedestrian
0 -1 1 /data/jaad/image/0316/pedestrian/00...
1 -1 0 /data/jaad/image/0316/ped1/0001.png
2 -1 0 /data/jaad/image/0316/ped2/0001.png
df2
pred true pedestrian
0 0.628186 1 /data/jaad/image/0316/pedestrian/00...
1 0.171355 0 /data/jaad/image/0316/ped1/0001.png
2 0.628186 1 /data/jaad/image/0316/pedestrian/00...
output
pred true pedestrian
0 0.628186 1 /data/jaad/image/0316/pedestrian/00...
1 -1 0 /data/jaad/image/0316/ped1/0001.png
2 -1 0 /data/jaad/image/0316/ped2/0001.png