Skip to content
Advertisement

Pandas filter without ~ and not in operator

I have two dataframes like as below

JavaScript

I would like to do the below

a) Check whether the ID and Name from df1 is present in df2.

b) If present in df2, put Yes in Status column or No in Status column. Don’t use ~ or not in operator because my df2 has million of rows. So, it will result in irrelevant results

I tried the below

JavaScript

The above code gives matching ids and names between df1 and df2.

But I want to find the ids and names that are present in df1 but missing/absent in df2. I cannot use the ~ operator because it will return all the rows from df2 that don’t have a match in df1. In real world, my df2 has millions of rows. I only want to find the missing df1 ids and names and put a status column

I expect my output to be like as below

JavaScript

Advertisement

Answer

Expected ouput is for match by 3 columns:

JavaScript

With testing by isin solution is:

JavaScript

Because if match by 2 columns ouput is different:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement