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)

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容