将索引转换为 PANDAS 中的日期

Transforming an index to date in PANDAS

我有一个简单的 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')