我想应该像使用函数一样
pd.Window_mean(df.Returns, 5)
但它引发了AttributeError:模块'pandas'没有属性'Window'。我该怎么做才能让它发挥作用?我所指的功能的文档在这里是https://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.window.Window.mean.html
也许您需要使用rolling mean
,因为window_mean
已被弃用,即
df = pd.DataFrame({'B': [0, 1, 2, 2, 4,8, 5, 4, 2, 4,0, 1, 1,6, 4]})
df['B'].rolling(window=5).mean()
0 NaN
1 NaN
2 NaN
3 NaN
4 1.8
5 3.4
6 4.2
7 4.6
8 4.6
9 4.6
10 3.0
11 2.2
12 1.6
13 2.4
14 2.4
Name: B, dtype: float64