Let's say I have a dataframe like this
Fruit Color Weight
apple red 50
apple red 75
apple green 45
orange orange 80
orange orange 90
orange red 90
I would like to add a column with True or False according to the fact that Fruit and Color of row x are equal to Fruit and Color of row x+1, like this:
Fruit Color Weight Validity
apple red 50 True
apple red 75 False
apple green 45 False
orange orange 80 True
orange orange 90 False
orange red 90 False
I have tried the following, but there are some errors I guess, I am getting wrong results:
g['Validity'] = (g[['Fruit', 'Color']] == g[['Fruit', 'Color']].shift()).any(axis=1)