简体   繁体   English

python statsmodels.tsa.seasonal中的值错误

[英]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.

相关问题 如何将 statsmodels.tsa.seasonal.seasonal_decompose 与 pandas dataframe 一起使用 - How to use statsmodels.tsa.seasonal.seasonal_decompose with a pandas dataframe Python - Statsmodels.tsa.seasonal_decompose - 缺少数据帧头部和尾部的值 - Python - Statsmodels.tsa.seasonal_decompose - missing values in head and tail of dataframe 如何解决错误unfunc'isfinite'以便在python中创建季节性statsmodel? - How to resolve error unfunc 'isfinite' in order to create a seasonal statsmodels in python? 如何为statsmodels.api.tsa.seasonal_decompose制作单面(仅过去值)过滤器 - How to make a one-sided (past values only) filter for statsmodels.api.tsa.seasonal_decompose 将特定的statsmodel拉到python3以获得statsmodels.tsa.johansen - pulling a particular statsmodel to python3 to get statsmodels.tsa.johansen python statsmodels.tsa.stattools.pacf与蒙面数组? - python statsmodels.tsa.stattools.pacf with masked array? R forecast.holt vs Python statsmodels.tsa.holtwinters - R forecast.holt vs Python statsmodels.tsa.holtwinters Python seasonal_decompose function 来自 Statsmodels 库给出 ValueError - Python seasonal_decompose function from Statsmodels library giving ValueError 仅使用本地python从statsmodels编写代码Season_decompose - Code seasonal_decompose from statsmodels with only native python 如何在 python 中获取 statsmodels.tsa.holtwinters-ExponentialSmoothing 模型的置信区间? - How to take confidence interval of statsmodels.tsa.holtwinters-ExponentialSmoothing Models in python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM