【问题标题】:Transforming an index to date in PANDAS在 PANDAS 中将索引转换为日期
【发布时间】:2016-05-02 12:30:49
【问题描述】:

我有一个简单的 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 了解它是每日频率的日期?非常感谢您的帮助。

【问题讨论】:

    标签: python pandas statsmodels


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2018-10-30
      • 2017-07-11
      • 2020-11-06
      • 2016-04-26
      • 2017-02-11
      • 1970-01-01
      • 2023-03-09
      • 2018-03-03
      相关资源
      最近更新 更多