AndreasInfo
AndreasInfo

Reputation: 1227

How to query in dataframe combined with .shift()

I have a temporary df like

tmp = df.loc[(df['Home Team'] == team) | (df['Away Team']== team)]

I would like to get a shifted value of a specific row. I tried

tmp.loc[(df['Primary Key'] == key)].shift(1)

but this obviously reduces the df first, so shift(1) will result in a non existing row. Any help to achieve this?

Upvotes: 2

Views: 332

Answers (1)

jezrael
jezrael

Reputation: 863331

You can first shifting column and then compare:

tmp.loc[(tmp['Primary Key'].shift(1) == key)]

Upvotes: 2

Related Questions