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()时都失败了
答案 0 :(得分:1)
pandas
模块本身没有方法rolling
。您应该将其作为实例化的DataFrame
类的方法来调用,例如
df[['data1','data2']].rolling(window=3)