For the following table:
Using Pandas – I would like achieve the desired_output column, that is TRUE when the value below the current cell i different – otherwise FALSE.
I have tried the following code – but error occurs.
df['desired_output']=df.two.apply(lambda x: True if df.iloc[int(x),1]==df.iloc[int(x+1),1] else False)
df['desired_output'] = df['city'].shift().bfill() != df['city']
6 People found this is helpful