baruchl
baruchl

Reputation: 229

Python Pandas time series groupby not behaving as expected

I have a data frame that looks like this:

df.head() enter image description here df.dtypes

enter image description here

df.index.dtype

enter image description here

The problem is resampling the data and getting correct results on different time periods.

e.g:

# count frame drops per second - works correctly
df.to_period(freq='S').groupby('ts')['frame_drop_issue'].sum()

enter image description here

# count frame drops per minute - works correctly
df.to_period(freq='T').groupby('ts')['frame_drop_issue'].sum()

enter image description here

But, if I try to aggregate by a period of 2 seconds, I get wrong results (similar as one second result)

# count frame drops per 2 seconds- wrong result
df.to_period(freq='2S').groupby('ts')['frame_drop_issue'].sum()

enter image description here

What am i doing wrong?

Upvotes: 0

Views: 53

Answers (1)

najeem
najeem

Reputation: 1921

to_period probably doesn't work with multiples of frequency. It's still an open issue https://github.com/pandas-dev/pandas/issues/14070. Instead you can use resample.

df.resample('2S')['frame_drop_issue'].sum()

Upvotes: 1

Related Questions