title: Python Pandas: How to make a column row dependent on it's previous rows, possibly with a function?
body: <p>I am trying to calculate column B in dependence of previous data of Column A and B. A simple function example would be</p>
  
  <p>e.g. <em>B(n) = A(n-1) + B(n-1)</em>, </p>
  
  <p>where <em>n</em> is the index of the Pandas dataframe. I do not need necessarily to use the dataframe index. </p>
  
  <p>In this example, I start with B(1) = 0 and add the A rows in consecutive fashion.</p>
  
  <pre><code>n    A(n)   B(n)
  ----------------
  1     1      0
  2     0      1
  3     2      1
  4     9      3
  </code></pre>
  
  <p>An example of this data structure would be defined in Pandas as</p>
  
  <pre><code>d = {'A' : pd.Series([1, 0, 2, 9],),
       'B' : pd.Series([0, float("nan"), float("nan"), float("nan")])}
  
  df = pd.DataFrame(d)
  </code></pre>
  
  <hr>
  
  <p><strong>Update</strong></p>
  
  <p>Both Henry Cutchers' and Jakob's answer work well. </p>