TypeError使用statsmodels.tsa.seasonal

时间:2017-09-26 17:01:36

标签: time-series statsmodels

我试图分解时间序列。我的日期不包含Nan和inf,其索引是' datetime64 [ns]。但出于某些原因,我无法理解,运行以下内容:

statsmodels.tsa.seasonal.seasonal_decompose(data, model='additive',filt=None, freq=None, two_sided=True)

给了我以下错误:

TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

我的数据如下:

ds
2005-01-01    1.56832e+06
2005-02-01    1.77795e+06
2005-03-01    1.89924e+06
2005-04-01    2.19562e+06
2005-05-01    2.25281e+06
2005-06-01    2.20942e+06
2005-07-01    2.13806e+06
2005-08-01    2.15816e+06

我从数据框中获取此系列文章:

    y   ds
ds      
2005-01-01  1.56832e+06 2005-01-01 00:00:00
2005-02-01  1.77795e+06 2005-02-01 00:00:00
2005-03-01  1.89924e+06 2005-03-01 00:00:00
2005-04-01  2.19562e+06 2005-04-01 00:00:00
2005-05-01  2.25281e+06 2005-05-01 00:00:00

使用以下代码:

df.columns = ['y','ds']
df[~df.isin([np.nan, np.inf, -np.inf]).any(1)]
df.index= df.ds
data = df.y      #data is the time series I want to decompose

系统信息:Python 3.5.1 |熊猫0.20.3 | Windows 7 64位

1 个答案:

答案 0 :(得分:0)

这里的问题相同。

检查类型是否为整数。如果不是,请转换它。

data.dtypes
dtype('int32')