[英]value error in python statsmodels.tsa.seasonal
I have this dataframe with date time indices:我有这个带有日期时间索引的数据框:
ts_log:
date price_per_unit
2013-04-04 12.762369
2013-04-05 12.777120
2013-04-06 12.773146
2013-04-07 12.780774
2013-04-08 12.786835
I have this piece of code for decomposition
我有这段代码用于decomposition
from statsmodels.tsa.seasonal import seasonal_decompose
decomposition = seasonal_decompose(ts_log)
trend = decomposition.trend
seasonal = decomposition.seasonal
residual = decomposition.resid
but in the line decomposition = seasonal_decompose(ts_log)
i got this error :但在行decomposition = seasonal_decompose(ts_log)
我得到这个错误:
ValueError: You must specify a freq or x must be a pandas object with a timeseries index
Where is the problem?问题出在哪里?
After some searching i found [here][1] that, i have to add values
to ts_log.price
经过一番搜索,我发现 [here][1],我必须将values
添加到ts_log.price
decomposition = seasonal_decompose(ts_log.price.values, freq=30)
Edit as to comments.编辑评论。 Adding just freq=30
is enough!添加freq=30
就足够了!
You can avoid this error by:您可以通过以下方式避免此错误:
ts_log = ts_log.asfreq('d')
this may generate some missing values:这可能会产生一些缺失值:
ts_log = ts_log.fillna(method='bfill').fillna(method='ffill')
以下已解决错误:
decomposition = seasonal_decompose(log_county_data , period = 30)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.