I have three columns: year, return, growth_of_1k. What I'd like to so is calculate the growth of $1,000 using the return column, and save it to growth_of_1k.
To visualize, here's what my dataframe currently looks like:
| year | return | growth_of_1k |
|---|---|---|
| 2010 | 0.1 | 1000 |
| 2011 | 0.4 | NaN |
| 2012 | 0.3 | NaN |
What I'd like to do is take the previous year's growth_of_1k and multiply it by this year's return.
Right now I have this:
df['growth_of_1k'] = df['growth_of_1k'].shift(1) * (1 + df['return'])
However, the code above only updates the second row, and nothing else. Any idea on how I can accomplish this?