TypeError 使用 statsmodels.tsa.seasonal [英] TypeError using statsmodels.tsa.seasonal

查看:16
本文介绍了TypeError 使用 statsmodels.tsa.seasonal的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to decompose a time series. my date doesn't contain Nan and inf and its index is 'datetime64[ns]. yet for some reasons I can't understand, running the following :

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

我从一个数据框中得到这个系列:

I'm getting this series from a data frame:

    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 位

System Info: Python 3.5.1 | Pandas 0.20.3 | Windows 7 64-bit

推荐答案

同样的问题.

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

Check if the type is an integer. If it is not, convert it.

data.dtypes
dtype('int32')

这篇关于TypeError 使用 statsmodels.tsa.seasonal的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆