【问题标题】:pandas Identify cycles in a timeseries datapandas 识别时间序列数据中的循环
【发布时间】:2022-07-19 03:36:06
【问题描述】:

我有时间序列数据,我想确定每个周期的周期和持续时间

  • 日期时间索引没有频率(数据点之间没有固定的时间步长)

我尝试使用来自statsmodels.tsa.seasonalseasonal_decompose 分解该系列,但出现以下错误ValueError: You must specify a period or x must be a pandas object with a DatetimeIndex with a freq not set to None

【问题讨论】:

  • 你能提供一个可重现的数据集吗?

标签: python pandas time-series statsmodels


【解决方案1】:

首先在变量 y 中重新采样处理后的 DataFrame(确保索引是日期时间类型)

然后在seasonal_decompose中传递该变量

例如:

y = df['Sales'].resample('MS').mean()
x = seasonal_decompose(y)
#plot the decomposed data
x.plot()
#show the plot
plt.show()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-01-31
    • 2019-05-11
    • 2019-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-22
    相关资源
    最近更新 更多