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

在调用数据分解函数decomposition = seasonal_decompose(timeseries)时出现以下错误:

  • AttributeError: 'Index' object has no attribute 'inferred_freq'
    这是由于索引不是时间索引,不具有inferred_freq属性导致的
    可在引入数据时自行生成时间索引解决该问题,如下:
df = pd.DataFrame(pd.read_excel(filename)) 
df.index = pd.DatetimeIndex(start=df['日期'][0],periods=len(df['日期']),freq='MS')  #生成日期索引
ts = df['数据']  # 生成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
    这是由于时间索引的频率不清楚不明确导致的错误
    可在执行分解函数时手动输入时间频率,如下:
decomposition = seasonal_decompose(timeseries, freq=1)

具体分析及解释见下一篇博文

你可能感兴趣的:(python3 error:'Index' object has no attribute 'inferred_freq')