Skip to content
Advertisement

Uncommon rows based on a column in pandas

Suppose I have two dataframes:

JavaScript

and

JavaScript

I want to use the second df as reference and drop those rows that exist in df2 from df1, so the result would be

JavaScript

I tried:

JavaScript

but this gives me the following:

JavaScript

Advertisement

Answer

Use Series.isin with inverted mask by ~ in boolean indexing, working well if need test only one column:

JavaScript

If need test 2 or more columns use DataFrame.merge with indicator parameter and then test in if column is not both:

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