pandas python statsmodels.tsa.seasonal中的值错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40794282/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
value error in python statsmodels.tsa.seasonal
提问by reza_v
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
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?
问题出在哪儿?
采纳答案by reza_v
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)
decomposition = seasonal_decompose(ts_log.price.values, freq=30)
Editas to comments. Adding just freq=30
is enough!
编辑评论。添加freq=30
就够了!
回答by Fares Sayah
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')