如何使用pandas.core.window.Window.mean函数?

问题描述 投票:1回答:1

我想应该像使用函数一样

    pd.Window_mean(df.Returns, 5)

但它引发了AttributeError:模块'pandas'没有属性'Window'。我该怎么做才能让它发挥作用?我所指的功能的文档在这里是https://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.window.Window.mean.html

python pandas window
1个回答
0
投票

也许您需要使用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
© www.soinside.com 2019 - 2024. All rights reserved.