gpt4 book ai didi

python - Pandas 0.23.1属性错误: 'module' object has no attribute 'rolling'

转载 作者:行者123 更新时间:2023-12-01 09:17:49 25 4
gpt4 key购买 nike

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()时都失败了

最佳答案

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

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

关于python - Pandas 0.23.1属性错误: 'module' object has no attribute 'rolling' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51076906/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com