在調(diào)用數(shù)據(jù)分解函數(shù)decomposition = seasonal_decompose(timeseries)時出現(xiàn)以下錯誤:
- AttributeError: 'Index' object has no attribute 'inferred_freq'
這是由于索引不是時間索引,不具有inferred_freq屬性導(dǎo)致的
可在引入數(shù)據(jù)時自行生成時間索引解決該問題,如下:
df = pd.DataFrame(pd.read_excel(filename))
df.index = pd.DatetimeIndex(start=df['日期'][0],periods=len(df['日期']),freq='MS') #生成日期索引
ts = df['數(shù)據(jù)'] # 生成pd.Series對象
- ValueError: freq N not understood. Please report if you think this is in error.
ValueError: You must specify a freq or x must be a pandas object with a timeseries index
這是由于時間索引的頻率不清楚不明確導(dǎo)致的錯誤
可在執(zhí)行分解函數(shù)時手動輸入時間頻率,如下:
decomposition = seasonal_decompose(timeseries, freq=1)
具體分析及解釋見下一篇博文