Home > OS >  Merging 2 data frames with different number of rows based on a column
Merging 2 data frames with different number of rows based on a column

Time:10-01

I have 2 dataframes:

  1. A = col (Ids, a,b,c,d); size = 40*5
  2. B = col (Ids,y,z); size =100*3

I need to get it as follows: C = col (Ids,a,b,c,d,y,z) only where A.ids = B.ids

I tried merge and concat, but not reaching the right ans.

Thanks in advance

CodePudding user response:

Make sure that the columns merged have the same dtype and then use pandas.merge :

C = A.merge(B, on="Ids") # how="inner" by default
  • Related