擅长:python、mysql、java
<p>您可能想在AAPL列中应用累积乘积。您当前的尝试无效,因为每行<code>.apply</code>有效。因此,每次为单个数字调用<code>np.cumprod</code>,而不是为数字数组调用</p>
<p>相反,请尝试以下方法:</p>
<pre><code>import pandas as pd
import numpy as np
aapl = {"AAPL": np.linspace(1, 2, 10)}
df = pd.DataFrame(appl)
# Calculate exp for the column, then calculate
# the cumulative product over the column
df['cum-AAPL'] = np.exp(df['AAPL']).cumprod())
</code></pre>