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 |
CodePudding user response:
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))]