Get the differences from two dataframes

Question:

I have the following dataframe:

country coin
USA coin1
USA coin2
Mexico coin3

Each coin is unique, and it can change the country. For example:

country coin
USA coin1
Mexico coin2
Mexico coin3

What I’m trying to find is a way to see which lines have changed. My desired output:

country coin
Mexico Coin2
Asked By: Vinícius Tomazoni

||

Answers:

You could use concat to combine them, and then use drop_duplicates to get the difference. For example:

concat([df1,df2]).drop_duplicates(keep=False)

EDIT:

To get just the one row, you can get the negation of everything common between the two dataframes by turning applying list to them and using .isin to find commonalities.

df1[~df1.apply(list,1).isin(df2.apply(list,1))]

Answered By: Matt Eng
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.