【发布时间】:2021-10-26 04:44:02
【问题描述】:
我的熊猫版本是 1.1.3,我正在尝试运行从this question 接受的答案中获得的代码,但是
offset = pd.offsets.timedelta(days=-6)
给出了我标题中提到的错误,timedelta 已导入但没有运气。我怎样才能让它正常运行?
【问题讨论】:
我的熊猫版本是 1.1.3,我正在尝试运行从this question 接受的答案中获得的代码,但是
offset = pd.offsets.timedelta(days=-6)
给出了我标题中提到的错误,timedelta 已导入但没有运气。我怎样才能让它正常运行?
【问题讨论】:
因为有警告:
FutureWarning:.resample() 和 Grouper() 中的“loffset”已弃用。
您可以在resample 天后用减法6 更改解决方案:
from pandas.tseries.frequencies import to_offset
df = df.resample('W').apply(logic)
df.index -= to_offset("6D")
#alternative
#df.index = df.index - to_offset("6D")
print (df)
Open High Low Close Volume
Date
2010-01-04 38.660000 40.700001 38.509998 40.290001 5925600
2010-01-11 40.209999 40.970001 39.279999 40.450001 6234600
【讨论】: