I'm looping through a dataframe (sorry, I know that's not ideal) and I wanted to check (at a certain point, for example i=n) if the current value on the column 'SKU', is present in the previous (n-1) values, so I tried:
if df['SKU'][i] not in df['SKU'][:i-1]:
but it's not working. Any help is greatly appreciated
CodePudding user response:
>>> df.SKU == df.SKU.shift()
CodePudding user response:
By way of trial and error, I figured I just needed to use .values at the end of the comparison like so:
if df['SKU'][i] not in df['SKU'][:i-1].values:
Thanks!