【问题标题】:None freq not allowing seasonal_decompose无频率不允许季节性分解
【发布时间】:2019-03-29 11:12:56
【问题描述】:

尝试对频率不规则的时间序列数据应用seasonal_decompose。它看起来像这样:

            modal_price
Period  
2014-11-01  1469
2015-01-01  1258
2015-03-01  1112
2015-04-01  1373
2015-06-01  1370
2015-07-01  1406
2015-08-01  1520
2015-09-01  1860
2015-10-01  1436
2015-11-01  1455

当我使用 df.index.freq 时,freq 为 None

当我像这样使用seasonal_decompose函数时:

seasonal_decompose(x, model = 'additive')

显示错误

ValueError: You must specify a freq or x must be a pandas object with a timeseries index with a freq not set to None.

需要帮助。

【问题讨论】:

    标签: python dataframe time time-series decomposition


    【解决方案1】:

    Statsmodel 需要频率来分解系列。

    通常,该频率在索引的元数据中(每天、每周、每月……)。但是,你的没有,这就是它给你这个错误的原因。

    至少有两种方法可以解决它(让我们考虑名为xdf):

    • @A.Abs 提到的那个,您将在seasonal_decompose 中传递freq,例如seasonal_decompose(x['Price'], freq=365)

    • 将频率设置为一个人的索引列为x.index.adfreq(freq='d'),其中'd' 对应于日期(每日频率)。

    有关可传递到 freq 关键字参数的频率字符串(或偏移别名)的更多信息,请查看 this answerthis Pandas Documentation page

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题,并通过指定频率参数来解决它。

      seasonal_decompose(Ts, model = 'additive', freq=1)
      

      我希望这会有所帮助。 我发现https://www.analyticsvidhya.com/blog/2016/02/time-series-forecasting-codes-python/ 很有帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-05-02
        • 2016-09-28
        • 1970-01-01
        • 2018-05-16
        • 2021-09-30
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多