title: Access the result of a previous calculation in custom function passed to apply()
body: <p>I'm working with Pandas in Python and I would like to access the result of the previous calculation when applying a custom function to a series. </p>
  
  <p>Roughly like this:</p>
  
  <pre><code>import pandas
  
  # How can I obtain previous_result?
  def foo(value, previous_result = None):
  
      # On the first iteration there is no previous result
      if previous_result is None:
          previous_result = value
  
      return value + previous_result
  
  series = pandas.Series([1,2,3])
  print(series.apply(foo))
  </code></pre>
  
  <p>This can also be generalized to "How to pass the <code>n</code> previous results to the function?". I know about <code>series.rolling()</code> but even with rolling I wasn't able to obtain the previous <em>results</em>, only the previous values of the input series.</p>