Wednesday, 30 June 2021

Why does using merge function in two different dataframes results me more rows?

I have two dataframes of the shape: (4000,3) (2000,3) , with the bellow info and cols:

df1:

imo speed length
1 1 4
1 2 4
2 10 10
2 12 10

df2:

imo dwt name
1 52 test1
2 62 test2
3 785 test3
4 353 test4

i would like to add column dwt of df2 to df1 based on the same imo.

imo speed length dwt
1 1 4 52
1 2 4 52
2 10 10 62
2 12 10 62

but when i am trying to do pd.merge(df1,df2, on = 'imo', how = 'inner') , the result is much more rows than the original shape of df1 how is that possible?



from Why does using merge function in two different dataframes results me more rows?

No comments:

Post a Comment