Home > Net >  How to copy the value of a column into a new column
How to copy the value of a column into a new column

Time:10-28

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!

CodePudding user response:

You can always do

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