0

I want to compare values of two same columns with with different data frame

DF1
  id         values_externalCode
  3DR_Ntype   PRO_END
  3DR_NType   CON_END
  abc         a

DF2
  id         values_externalCode
  3DR_Ntype   PRO_END
  3DR_NType   CON_END
  abc         b

the code below which is i m using just compare same data frame column value

match = data_frame1.loc[(data_frame1['id'] ==data_frame1['id']) & (data_frame1['values_externalCode'] == data_frame1['values_externalCode'])]

if i m using below code for comparing two dataframes columns it gives me an error

match = data_frame1.loc[(data_frame1['id'] ==data_frame2['id']) & (data_frame1['values_externalCode'] == data_frame2['values_externalCode'])]

ValueError: Can only compare identically-labeled Series objects

My Question is how to compare two same columns values between two different data frames and only show match records of the two same column values between two data frames

Any Help would be appreciated thanks in Advance

Expected result

  DF1
  id         values_externalCode
  3DR_Ntype   PRO_END
  3DR_NType   CON_END

Umair Mubeen
  • 823
  • 4
  • 22
  • 1
    what about a plain merge `df1.merge(df2,on=['id','values_externalCode'])` – anky Mar 14 '20 at 17:07
  • 1
    @anky_91 already posted the central concept. If your codes are not unique, you'll need to merge instead on *both* columns being equal: use one as key, and the other as filter. – Prune Mar 14 '20 at 17:19
  • but i have sheet which have more than sixty thousands records and most of them have same columns and have same values – Umair Mubeen Mar 14 '20 at 17:21
  • @UmairMubeen you can edit your example to show why it is not a dupe. We will reopen it post your edit once confirmed. – anky Mar 14 '20 at 17:22

0 Answers0