Loreln
Loreln

Reputation: 201

How to copy the value of a column into a new column

Hi! Do you know how I could copy the value of a cell [Column "DATA_2] into a new column [Column "NEW_DATA"], but only if the value is "1" or "-1" and it must be copied 2 cells above the original cell? (all other cells in the new column must be "0")

DataFrame

I'm using Pandas, could you at least help me get an idea of what functions to use?

Thank you!

Upvotes: 2

Views: 358

Answers (1)

BENY
BENY

Reputation: 323266

You can always do

df['new_data'] = df['DATA_2'].shift(-2).fillna(0)

Upvotes: 2

Related Questions