我有以下代码,可使用statsmodel分解时间序列数据,但会出错:
import pandas as pd
import numpy as np
from pandas import datetime
from statsmodels.tsa.seasonal import seasonal_decompose
# load data
def parser (x):
return datetime.strptime(x,'%d/%m/%Y')
orders = pd.read_csv('time_series_total.csv',index_col=0,parse_dates= [0],date_parser=parser,header=0)
#Decompose time-series
# Multiplicative Decomposition
result_mul = seasonal_decompose(orders['orders'],
model='multiplicative',extrapolate_trend='freq')
# Additive Decomposition
result_add = seasonal_decompose(orders['orders'],
model='additive',extrapolate_trend='freq')
它显示此错误:
ValueError: operands could not be broadcast together with shapes (32,) (74,)
这是我加载和打印时的时间序列数据(前5个):
orders
weeks
2019-03-11 43
2019-03-18 14
2019-03-25 2
2019-04-01 229
2019-04-08 46