Home > Enterprise >  Filling a new column with values from a different column
Filling a new column with values from a different column

Time:11-13

Supposing I have a dataframe like so : dataframe

If I have to make a new column, which has the values from column 3 like so 4 N/A -1.135632 -1.044236 1.071804 0.271860 -1.087401 0.524988 -1.039268 0.844885 -1.469388 -0.968914

i.e, entry 1 of column 4 is filled with entry 0 of column 3, entry 2 of column 4 is filled with entry 1 of column 3 and so on...until the nth entry in the 4th column is filled with the (n-1)th entry of the 3rd column

CodePudding user response:

df['column_4'] = df['column_3'].shift(1)

CodePudding user response:

Are you looking for Series.shift()?

df[4] = df[3].shift()
  • Related