title: Reference previous rows in Dataframe calculations (Pandas)
body: <p>I am trying to do a calculation where I add a new DataFrame column that calculates the average of the previous 2 values. Here is the desired outcome:</p>
  
  <pre><code>    Input    Prev. 2 Avg
  0   2        NaN
  1   2        NaN
  2   3        2.0
  3   3        2.5
  4   4        3.0
  5   4        3.5
  </code></pre>
  
  <p>Unfortunately I don't know how to reference the previous rows for the calculation. It works if I add two additional columns, one being the Input shifted 1, the other shifted 2. Then I can do the calculation across:</p>
  
  <pre><code> df["Input1"] = df["Input"].shift(1)
  
  df["Input2"] = df["Input"].shift(2)
  
  df["Prev. 2 Avg"] = (df["Input1"] + df["Input2"])/2
  </code></pre>
  
  <p>This just feels clunky and awkward, plus I am creating two new (unnecessary) columns.</p>
  
  <p>Any suggestions? </p>
  
  <p>Thank you!</p>