【发布时间】:2020-02-20 18:51:56
【问题描述】:
我有以下数据框
data = pd.DataFrame({
'date': [1988, 1988, 2000, 2005],
'value': [11558522, 12323552, 13770958, 18412280]
})
然后我将日期列变成日期时间数据类型
data['date'] = pd.to_datetime(data['date'],format = '%Y')
当我打印我得到的数据类型时
print(data.dtypes)
>>> Register No.
>>> date datetime64[ns]
>>> Sum int64
>>> dtype: object
然后我使用以下代码进行时间序列分解
from pylab import rcParams
from statsmodels.tsa.seasonal import seasonal_decompose
rcParams ['figure.figsize'] = 18,8
decomposition = seasonal_decompose(data, model='additive', freq=30)
fig = decomposition.plot()
但我得到以下错误
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-54-e3a60d7302da> in <module>
3
4 rcParams ['figure.figsize'] = 18,8
----> 5 decomposition = seasonal_decompose(data, model='additive', freq=30)
6
7 fig = decomposition.plot()
~/opt/anaconda3/lib/python3.7/site-packages/statsmodels/tsa/seasonal.py in seasonal_decompose(x, model, filt, freq, two_sided, extrapolate_trend)
113 nobs = len(x)
114
--> 115 if not np.all(np.isfinite(x)):
116 raise ValueError("This function does not handle missing values")
117 if model.startswith('m'):
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''
我的数据框中没有任何缺失值,我不确定为什么会出现此错误
【问题讨论】:
标签: python pandas dataframe time-series