I'm attempting to do a seasonal_decompose
on my pandas dataframe but I've encountered an error that I can't get past. My time series data contains chronological gaps which is sensible considering my data is stock prices (after market hours create these gaps, as well as differing month lengths, etc.). The data in of itself can be thought of as contiguous however pandas doesn't seem to want to infer any frequency.
All of my timeframe data (1m, 5m, 15m ... 1D, 1M) is populated correctly but with None set as the frequency. My algorithm creates an empty dataframe upon instantiation and adds values to it via loc
as the data arrives during the course of the algorithm's runtime. So perhaps that's ultimately why the frequency is None (as Pandas is typically used after all data is generated).
I've tried explicitly setting the frequency right before seasonal_decompose
using:
data.index.freq = data.index.freq or to_offset(timeframe.Timespan).freqstr
where timeframe.Timespan is a python timedelta object. The resulting string is accurate ("D" because the timespan happens to be daily) but the following error occurs:
ValueError: Inferred frequency None from passed values does not conform to passed frequency D
So I can't explicitly set the frequency on my index? How do I solve this? How is the frequency integer (being passed to seasonal_decompose
) derived from these strings anyway? I'm also not permitted to change the value of data.index.inferred_freq
so that's not an option.