Creating an empty Pandas DataFrame column with a fixed first value then filling it with a formula
<p>I'd like to create an emtpy column in an existing DataFrame with the first value in only one column to = 100. After that I'd like to iterate and fill the rest of the column with a formula, like row[C][t-1] * (1 + row[B][t])</p>

<p>very similar to:
<a href="http://stackoverflow.com/questions/13784192/creating-an-empty-pandas-dataframe-then-filling-it">Creating an empty Pandas DataFrame, then filling it?</a></p>

<p>But the difference is fixing the first value of column 'C' to 100 vs entirely formulas.</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')

columns = ['A','B','C']

df_ = pd.DataFrame(index=index, columns=columns)
df_ = df_.fillna(0)

data = np.array([np.arange(10)]*3).T
df = pd.DataFrame(data, index=index, columns=columns)

df['B'] = df['A'].pct_change()
df['C'] = df['C'].shift() * (1+df['B'])

## how do I set 2016-10-03 in Column 'C' to equal 100 and then calc consequtively from there?

df
</code></pre>

<p>Try this. Unfortunately, something similar to a for loop is likely needed because you will need to calculate the next row based on the prior rows value which needs to be saved to a variable as it moves down the rows (c_column in my example):</p>

<pre><code>c_column = []
c_column.append(100)

for x,i in enumerate(df['B']):
    if(x&gt;0):
        c_column.append(c_column[x-1] * (1+i))

df['C'] = c_column
</code></pre>

python pandas dataframe