python3 error:'Index' object has no attribute 'inferred_freq'

在調(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)

具體分析及解釋見下一篇博文

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容