Menu Close

How to use Python Pandas get rows which are NOT in other dataframe?

To use Python Pandas get rows which are NOT in other dataframe, we can use isin with negation.

For instance, we write

df1[~df1.index.isin(df2.index)]

to call isin with the index of the df1 data frame that are in fd2.inex list.

And then we negate that to get the rows in df1 that aren’t in the df2 data frame.

Posted in Python, Python Answers