擅长:python、mysql、java
<p>使用<a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.cumprod.html" rel="nofollow noreferrer">^{<cd1>}</a>:</p>
<pre><code>df['pct_change'] = (df['perf']+1).cumprod() * 100
</code></pre>
<p>实现您真正想要的:</p>
<pre><code>pct_change_0 = (perf_0 + 1) * 100
pct_change_1 = pct_change_0 * (perf_1 + 1) = (perf_0 + 1) * (perf_1 + 1) * 100
pct_change_2 = pct_change_1 * (perf_2 + 1) = (perf_0 + 1) * (perf_1 + 1) * (perf_2 + 1) * 100
...
</code></pre>
<p>因此,您实际上是在计算<code>perf</code>值(或者更准确地说<code>perf + 1</code>值)的累积乘积</p>