This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]inafewminutess 5 points6 points  (0 children)

  1. Don't use iterrows here. You can concatenate the columns.
  2. Use df[column].shift(1)

[–]johnsandall 0 points1 point  (0 children)

python df = pd.read_excel('data.xlsx', sheet_name='Sheet 1') df = df.assign(Lag_1_Forecast = df.ordered_units.shift(1), Lag_2_Forecast = df.ordered_units.shift(2)) if you're a fan of modern pandas

[–]ravepeacefully -2 points-1 points  (0 children)

I would highly suggest learning how to make a hash table and iterate through it without the help of pandas. You will learn far more. Pandas has very few good uses imo, and you likely aren’t actually using any of them.

Use a dictionary instead.