title: Adding columns to a pandas.DataFrame with previous row values before calling apply()
body: <p>I need to add a new column to a <code>pandas</code> <code>dataframe</code>, where the value is calculated from the value of a column <strong>in the previous row</strong>.</p>
  
  <p>Coming from a non-functional background (<code>C#</code>), I am trying to avoid loops since I read it is an anti-pattern.</p>
  
  <p>My plan is to use <code>series.shift</code> to add a new column to the <code>dataframe</code> for the previous value, call <code>dataframe.apply</code> and finally remove the additional column. E.g.:</p>
  
  <pre><code>def my_function(row):
    # perform complex calculations with row.time, row.time_previous and other values
    # return the result
  
  df["time_previous"] = df.time.shift(1)
  df.apply(my_function, axis = 1)
  df.drop("time.previous", axis=1)
  </code></pre>
  
  <p>In reality, I need to create four additional columns like this. Is there a better alternative to accomplish this without a loop? Is this a good idea at all?</p>