Finding the difference between to pandas data frames

Viewed 23

I am newish to python and trying to make sense of pythonic/pandas ways of doing things.

I have two data frames and I am trying to find the items in one that are not in the other.

df1   =pd.DataFrame({'items': ['shoes', 'socks', 'shoes'],
                     'coors': ['brown', 'red', 'black'],
                   'number': [1, 2, 3]})

df2   =pd.DataFrame({'items': ['shoes', 'socks', 'shoes'],
                     'coors': ['brown', 'red', 'pink'],
                   'number': [4, 5, 6]})

i.e.

fancy_subtract(df2,df1) = 3 brown shoes, 3 red socks,6 pink shoes
fancy_subtract(df1,df2) = 3 black shoes

I've tried subtracting the data frames (which didn't work for obvious reasons), clearly, you can do it via a for loop but that doesn't feel elegant, or like it is taking advantage of how python/pandas works.

0 Answers
Related