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

Question:

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

Asked By: baps

||

Answers:

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
Answered By: abokey