熊猫0.23.1 AttributeError:“模块”对象没有属性“滚动”

时间:2018-06-28 07:19:16

标签: python pandas

import pandas as pd
import numpy as np
from pandas import *

print (pd.__version__)
df = pd.DataFrame({'key1':['a','a','b','b','a'],
               'key2':['one','two','one','two','one'],
               'data1':np.nan,
               'data2':np.random.randn(5)})

df = pd.rolling(df[['data1','data2']],window = 3)
print (df)

返回:

0.23.1
Traceback (most recent call last):
  File "jj.py", line 33, in <module>
    df = pd.rolling(df[['data1','data2']],window = 3)
AttributeError: 'module' object has no attribute 'rolling'

我在计算机上尝试使用python2和python3,但是当我使用rolling()时都失败了

1 个答案:

答案 0 :(得分:1)

pandas模块本身没有方法rolling。您应该将其作为实例化的DataFrame类的方法来调用,例如

df[['data1','data2']].rolling(window=3)