擅长:python、mysql、java
<p>不是很好的解决方案,因为<a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.iterrows.html" rel="nofollow noreferrer">^{<cd1>}</a>循环:</p>
<pre><code>for i, row in index_pd.iterrows():
if i == 0:
index_pd.loc[i, 'value'] = index_pd['day_index'].iat[0]
else:
index_pd.loc[i, 'value'] = index_pd.loc[i,'percent'] * index_pd.loc[i-1, 'value']+ \
index_pd.loc[i-1, 'value']
print (index_pd)
tradedate percent day_index value
0 2015-06-02 0.0 1000 1000.0
1 2015-06-03 0.5 0 1500.0
2 2015-06-04 0.6 0 2400.0
</code></pre>