0

I have two dataframes, which I am trying to merge, but the result seems to be missing entries.

df1:

id file
1  file1
1  file2
3  some_file
3  some_other_file
3  test_file   
4  no_file

df2:

id  total  a load of other columns....
1   3.21   .   .   .  .     .
2   1.20   .   .   .  .     .
3   2.20   .   .   .  .     .
4   1.75   .   .   .  .     .

The result I want is:

id file.               total
1  file1               3.21
1  file2               3.21
3  some_file           2.20
3  some_other_file     2.20
3  test_file           2.20
4  no_file             1.75

I'm doing a merge:

new_df=df1.merge(df2[["id","total"]],how="inner",left_on="id",right_on="id")

but I suspect I am misunderstanding how merge works, as i find that new_df has missing elements.

Is this the correct way to do the merge, or am I missing something?

abinitio
  • 609
  • 6
  • 20

0 Answers0