0

I have two data frame wants to compare some fields between two and if filed found in both the data frame then flag it to true else false. here StoreId And PartyCode is a composite key.

Code:

df1 = DataFrame({'StoreId': [1, 2, 3], 'PartyCode': ['a', 'b', 'c'],'anotherfiled': ['x', 'y', 'z']})
df2 = DataFrame({'StoreId': [1, 5,4], 'PartyCode': ['a', 'b','d']})
df1.isin(df2)

Expected Output: enter image description here

Juned Ansari
  • 5,035
  • 7
  • 56
  • 89

1 Answers1

2

You have to specify the column you want to check.

df1.loc[:, "flag"] = df1['PartyCode'].isin(df2['PartyCode'])
df1

So your output is the same as you requested.

    StoreId PartyCode   anotherfiled    flag
0     1       a            x            True
1     2       b            y            True
2     3       c            z            False
sergiomahi
  • 964
  • 2
  • 8
  • 21