python-3.x - `start` 参数无法与与数据索引相关的位置匹配

标签 python-3.x google-colaboratory

我不知道为什么我的“开始”pred 不能工作。我只是在 pd.to_datetime 上添加了一些编辑,但没有任何效果。我很困惑如何解决这个问题。
这是我的代码

    pred = results.get_prediction(start=pd.to_datetime('2018-06-01'), dynamic=False)
    pred_ci = pred.conf_int()
    ax = y['2015':].plot(label='observed')
    pred.predicted_mean.plot(ax=ax, label='One-step ahead Forecast', alpha=.7, figsize=(14, 4))
    ax.fill_between(pred_ci.index,
                    pred_ci.iloc[:, 0],
                    pred_ci.iloc[:, 1], color='k', alpha=.2)
    ax.set_xlabel('Date')
    ax.set_ylabel('Retail_sold')
    plt.legend()
    plt.show()

并且我的错误日志总是引用我的时间格式,我不得不重新采样我的数据,从每日数据到每月数据,然后再开始数据分析和解决数据,但我不知道为什么我的数据不能使用 pd.todatetime 读取。
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
pandas/_libs/index.pyx in pandas._libs.index.DatetimeEngine.get_loc()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()

KeyError: 1546300800000000000

During handling of the above exception, another exception occurred:

KeyError                                  Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
   2896             try:
-> 2897                 return self._engine.get_loc(key)
   2898             except KeyError:

pandas/_libs/index.pyx in pandas._libs.index.DatetimeEngine.get_loc()

pandas/_libs/index.pyx in pandas._libs.index.DatetimeEngine.get_loc()

KeyError: Timestamp('2019-01-01 00:00:00')

During handling of the above exception, another exception occurred:

KeyError                                  Traceback (most recent call last)
pandas/_libs/index.pyx in pandas._libs.index.DatetimeEngine.get_loc()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()

KeyError: 1546300800000000000

During handling of the above exception, another exception occurred:

KeyError                                  Traceback (most recent call last)
11 frames
pandas/_libs/index.pyx in pandas._libs.index.DatetimeEngine.get_loc()

pandas/_libs/index.pyx in pandas._libs.index.DatetimeEngine.get_loc()

KeyError: Timestamp('2019-01-01 00:00:00')

During handling of the above exception, another exception occurred:

KeyError                                  Traceback (most recent call last)
pandas/_libs/index.pyx in pandas._libs.index.DatetimeEngine.get_loc()

pandas/_libs/index.pyx in pandas._libs.index.DatetimeEngine.get_loc()

KeyError: Timestamp('2019-01-01 00:00:00')

During handling of the above exception, another exception occurred:

KeyError                                  Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/statsmodels/tsa/base/tsa_model.py in _get_prediction_index(self, start, end, index, silent)
    522             start, start_index, start_oos = self._get_index_label_loc(start)
    523         except KeyError:
--> 524             raise KeyError('The `start` argument could not be matched to a'
    525                            ' location related to the index of the data.')
    526         if end is None:

KeyError: 'The `start` argument could not be matched to a location related to the index of the data.'

任何人都可以解决我的问题吗?
我使用了 google colab 和 python 3.7

最佳答案

这里的潜在问题是您的数据没有关联频率的索引,因为您的数据跳过了几天(例如从 2016/2/5 到 2016/2/14)。

关于python-3.x - `start` 参数无法与与数据索引相关的位置匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58580633/

相关文章:

gpu - 在 Google Colab 上请求特定类型的 GPU

python-3.x - 如何使用 Pandas 在 Python 中对字典中的数据进行排序

python - 正则表达式匹配相同分隔符之间的多个结果

python-3.x - 找不到使用 python 程序创建的 postgres 表

python - 函数名后的键名

markdown - 是否可以在 Colab 中用 Markdown 替换表单标题?

python - 更改 "Quit the server with CTRL-BREAK."

python - 张量板 : No dashboards active for current dataset

jupyter-notebook - 如何在 Google Colab 中做内部链接

python - 属性错误 : 'google.protobuf.pyext._message.RepeatedCompositeCo' object has no attribute 'append'