【问题标题】:TypeError: int() argument must be a string, object or a number, not 'Timestamp'TypeError: int() 参数必须是字符串、对象或数字,而不是“时间戳”
【发布时间】:2019-06-27 21:00:02
【问题描述】:

输入:
pred = results.get_prediction(start=pd.to_datetime('2015-06-01'),axis=0)

输出:

    TypeError                                 Traceback (most recent call last)
<ipython-input-69-f9b333cfd215> in <module>()
----> 1 pred = results.get_prediction(start=pd.to_datetime('2015-06-01'),axis=0)
      2 pred_ci = pred.conf_int()

~\Anaconda3\lib\site-packages\statsmodels\tsa\statespace\sarimax.py in get_prediction(self, start, end, dynamic, index, exog, **kwargs)
   1924         # Handle start, end, dynamic
   1925         _start, _end, _out_of_sample, prediction_index = (
-> 1926             self.model._get_prediction_index(start, end, index, silent=True))
   1927 
   1928         # Handle exogenous parameters

~\Anaconda3\lib\site-packages\statsmodels\tsa\base\tsa_model.py in _get_prediction_index(self, start, end, index, silent)
    475         # indexes.
    476         try:
--> 477             start, start_index, start_oos = self._get_index_label_loc(start)
    478         except KeyError:
    479             raise KeyError('The `start` argument could not be matched to a'

~\Anaconda3\lib\site-packages\statsmodels\tsa\base\tsa_model.py in _get_index_label_loc(self, key, base_index)
    410         try:
    411             loc, index, index_was_expanded = (
--> 412                 self._get_index_loc(key, base_index))
    413         except KeyError as e:
    414             try:

~\Anaconda3\lib\site-packages\statsmodels\tsa\base\tsa_model.py in _get_index_loc(self, key, base_index)
    351             # RangeIndex)
    352             try:
--> 353                 index[key]
    354             # We want to raise a KeyError in this case, to keep the exception
    355             # consistent across index types.

~\Anaconda3\lib\site-packages\pandas\core\indexes\range.py in __getitem__(self, key)
    496 
    497         if is_scalar(key):
--> 498             n = int(key)
    499             if n != key:
    500                 return super_getitem(key)

TypeError: int() argument must be a string, a bytes-like object or a number, not 'Timestamp'

【问题讨论】:

  • 什么是results?告诉我们您为什么认为此方法会接受时间戳作为参数。
  • 我正在使用时间序列模型 (ARIMA) 来进行预测。

标签: python pandas timestamp jupyter-notebook statsmodels


【解决方案1】:

使用 python 日期时间或字符串而不是 pandas datetime64:

results.get_prediction(start='2015-06-01', axis=0)
# or
import datetime as dt
results.get_prediction(start=dt.datetime(2015, 6, 1), axis=0)

应该在这里工作。

见the docs。

【讨论】:

  • 我试过这个并得到这个错误。 TypeError: int() argument must be a string, a bytes-like object or a number, not 'datetime.datetime'
  • @ShriDharani 也有第一个版本(字符串)?
猜你喜欢
  • 2019-03-02
  • 2014-02-26
  • 1970-01-01
  • 2019-07-07
  • 2019-05-22
  • 1970-01-01
  • 2019-07-07
  • 2023-03-29
相关资源
最近更新 更多