title: Pandas variable using lagged values
body: <p>I am trying to write Pandas code to calculate accounting depreciations. The math is very simple:</p>
  <pre><code>depreciation(t)=depr_rate * [cumsum(investments(t)) - cumsum(depreciation(t-1))]
  </code></pre>
  <p>For example (with a depreciation rate of 30%):</p>
  <p>Year 1: Investments 100 and depreciations 30
  Year 2: Investments 100 and depreciations 51
  Year 3: Investments   0 and depreciations 35.7</p>
  <p>I am looking for a way to do this in Pandas.</p>
  <p>My fix so far to convert the column to a list and then iterate over the list as follows:</p>
  <pre><code>inv_cum=list(df_inv.investment_cumsum)
  depr_list=[]
  for num in range(len(inv_cum)):
      depr_list.append(depr_rate*(inv_cum[num]-sum(depr_list[:max(0,num)])))
  df_inv['depreciations']=depr_list 
  </code></pre>
  <p>The fix works fine but I would prefer to use Pandas functionality. All help will be appreciated.</p>