1

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

Newbie
  • 23
  • 4
  • 2
    Please include your data in the body of your question as text so it can be copy-and-pasted and searched to help us help you; you can wrap text with three back-tics (`) to create a code block to format it nicely – ti7 Nov 12 '21 at 17:19
  • Does this answer your question? [How to shift a column in Pandas DataFrame](https://stackoverflow.com/questions/10982089/how-to-shift-a-column-in-pandas-dataframe) – Henry Woody Nov 12 '21 at 17:30

2 Answers2

1

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

maow
  • 2,712
  • 1
  • 11
  • 25
1

Are you looking for Series.shift()?

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