title: How to calculate with previous row value of a column if it can be declared only after it should be used in pandas dataframe?
body: <p>The following is the dataframe I have:</p>
  
  <pre><code>import datetime
  import pandas as pd
  import numpy as np
  
  todays_date = datetime.datetime.now().date()
  index = pd.date_range(todays_date-datetime.timedelta(10), periods=10, freq='D')
  data = pd.DataFrame(index=index)
  
  data['Open'] = np.random.randint(20,40, size=len(data))
  data['High'] = np.random.randint(40,50, size=len(data))
  data['Low'] = np.random.randint(10,20, size=len(data))
  data['Close'] = np.random.randint(10,20, size=len(data))
  </code></pre>
  
  <p>The calculations I would like to perform are the following:</p>
  
  <pre><code>capital = 30000
  
  data['Shares'] = (capital * 0.05 / data['Close'].shift(1) - data['Low'].shift(1)).round(0)
  data['Open_price'] = data['Open'] + 0.5 * (data['High'] - data['Open'])
  data['Floating_P/L'] = data['Shares'] * data['Close']
  data['Close_price'] = data['Close'] - 0.5 * (data['Close'] - data['Low'])
  data['Closed_P/L'] = data['Shares'].shift(1) * data['Close_price']
  data['Closed_Balance'] = capital + data['Closed_P/L'].cumsum()
  data['Equity'] = data['Closed_Balance'] + data['Floating_P/L']
  
  capital = data['Equity'].shift(1)
  </code></pre>
  
  <p>As you can see <code>Equity</code> is calculated from today's <code>Shares</code> number which is calculated from yesterday's <code>Equity</code>. I want to set <code>capital</code> to be the initial value of <code>Equity</code> at the first index and calculate <code>Shares</code> based on this number at the first index. From the second index, <code>Shares</code> should be calculated from the <code>Equity</code> shifted one row up. How can I do this?</p>