如何使用pandas.core.window.Window.mean函数?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何使用pandas.core.window.Window.mean函数?相关的知识,希望对你有一定的参考价值。
我想应该像使用函数一样
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
以上是关于如何使用pandas.core.window.Window.mean函数?的主要内容,如果未能解决你的问题,请参考以下文章
如何在自动布局中使用约束标识符以及如何使用标识符更改约束? [迅速]
如何使用 AngularJS 的 ng-model 创建一个数组以及如何使用 jquery 提交?