gpt4 book ai didi

python - 将 PANDAS 中的索引转换为最新日期

转载 作者:太空宇宙 更新时间:2023-11-03 16:39:13 25 4
gpt4 key购买 nike

我有一个简单的 PANDAS 数据框:

              V1
Index
1 5
2 6
3 7
4 8
5 9
6 10

我想拟合 statsmodels 中的 ARMA 模型。当我尝试这样做时,我得到以下结果:

 ValueError: Given a pandas object and the index does not contain dates

我猜这意味着索引没有设置为日期。如何将索引转换为日期?我认为当前索引为天,因此在上面的示例中,数据帧运行了 6 天。我怎样才能让 PANDAS/statsmodels 理解它是每日频率的日期?非常感谢您的帮助。

最佳答案

您可以将索引设置为每日结束于今天。

df.index = pd.DatetimeIndex(end=pd.datetime.today(), periods=len(df), freq='1D')

关于python - 将 PANDAS 中的索引转换为最新日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36974300/

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