Python中使用pandas报错“module 'pandas' has no attribute 'rolling_mean'”,问题原因及解决方法

断了今生、忘了曾经 提交于 2020-03-02 04:09:03

当在python 中使用对dataframe变量df_test使用如下语句时:

  pd.rolling_mean(df_test['col_name'], ma)

系统报错: module 'pandas' has no attribute 'rolling_mean' ,报错pandas没有rolling_mean属性。问题在于rolling_mean是pandas旧版本的功能,可以使用如下语句替换:

df_test['col_name'].rolling(ma).mean()

问题的根源在于:新版本pandas已经不支持rolling_mean()方法。另外可以使用pip install pandas安装新的pandas模块。

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!