擅长:python、mysql、java
<p>Pandas<code>rolling_mean</code>和<code>rolling_std</code>函数已被弃用,取而代之的是更通用的“滚动”框架。@elyase的示例可以修改为:</p>
<pre><code>import pandas as pd
import numpy as np
%matplotlib inline
# some sample data
ts = pd.Series(np.random.randn(1000), index=pd.date_range('1/1/2000', periods=1000)).cumsum()
#plot the time series
ts.plot(style='k--')
# calculate a 60 day rolling mean and plot
ts.rolling(window=60).mean().plot(style='k')
# add the 20 day rolling standard deviation:
ts.rolling(window=20).std().plot(style='b')
</code></pre>
<p><code>rolling</code>函数支持许多不同的窗口类型,如文档所述<a href="https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.rolling.html" rel="nofollow noreferrer">here</a>。可以对<code>rolling</code>对象调用许多函数,包括<code>var</code>和其他有趣的统计数据(<code>skew</code>、<code>kurt</code>、<code>quantile</code>等)。我一直坚持使用<code>std</code>,因为图与平均值在同一个图上,这在单位方面更合理。</p>