pandas Identify cycles in a timeseries data

Viewed 161

I have timeseries data and I want to identify cycles and duration of each cycle.

  • The datetime index does not have a frequency (there is no fixed time step between data point)

I tried to decompose the series using seasonal_decompose from statsmodels.tsa.seasonal but I got the following error ValueError: You must specify a period or x must be a pandas object with a DatetimeIndex with a freq not set to None

1 Answers

First resample your processed DataFrame in a variable say y (make sure that the index is of datetime type)

Then pass that variable in seasonal_decompose

Ex:

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