seasonal_decompose()需要一个freq,它作为DateTimeIndex元信息的一部分提供,可以由pandas.Index.inferred_freq推断,或者由用户推断为一个整数,给出每个周期的周期数.例如,每月12个(来自season_mean的docstring):
06000
为了说明 – 使用随机样本数据:
length = 400
x = np.sin(np.arange(length)) * 10 + np.random.randn(length)
df = pd.DataFrame(data=x, index=pd.date_range(start=datetime(2015, 1, 1), periods=length, freq='w'), columns=['value'])
DatetimeIndex: 400 entries, 2015-01-04 to 2022-08-28
Freq: W-SUN
decomp = sm.tsa.seasonal_decompose(df)
data = pd.concat([df, decomp.trend, decomp.seasonal, decomp.resid], axis=1)
data.columns = ['series', 'trend', 'seasonal', 'resid']
Data columns (total 4 columns):
series 400 non-null float64
trend 348 non-null float64
seasonal 400 non-null float64