0

I'm trying to decompose a time series using sm.tsa.seasonal_decompose() and I got a

ValueError: You must specify a period or x must be a pandas object with a >DatetimeIndex with a freq not set to None

I followed the suggestions of the answer here: decompose() for time series: ValueError: You must specify a period or x must be a pandas object with a DatetimeIndex with a freq not set to None

So I tried setting the frequency of my time to minutes since this was the frequency with which the data was recorded. To that end, I tried the following code:

df = df.set_index('timestamp').asfreq('T')
df.index = pd.to_datetime(df.index)

Where 'T' specifies that the frequency is in minutes. But this resulted in my dataframe having only null values. How can I fix this?

desertnaut
  • 57,590
  • 26
  • 140
  • 166
Squirtle
  • 129
  • 8

1 Answers1

0

so your code might be a little off. Would this work

df.index = pd.to_datetime(df.index)
df.set_index('timestamp', inplace=True)

Could you share and print out the results of this?

Pieter Geelen
  • 528
  • 2
  • 11
  • Turns out that some of the timestamps were never included but they were not represented in the dataframe as NaNs, rather the dataframe skipped that time all together. So when I incremented by minutes this added rows with NaN values and messed things up. I believe it's working now but I need to debug a bit more. If I find further issues, I'll bring it up.... or thank you and close this out. – Squirtle Jul 26 '22 at 17:20