Skip to content
Advertisement

pandas consecutive Boolean event rollup time series

Here’s some made up time series data on 1 minute intervals:

JavaScript

This is just some code to create some Boolean columns

JavaScript

On my screen this prints:

JavaScript

What I am trying to figure out is how to rollup per hour cumulative events (True or 1) but if there is no 0 between events, its the same event! Hopefully that makes sense what I was describing above on the <---- Count as same event!

If I do:

JavaScript

This will just resample and count all events, right regardless of the time series commitment I was trying to highlight with the <---- Count as same event!

Thanks for any tips!!

Advertisement

Answer

Check if the current row (“2019-01-01 00:02:00”) equals to 1 and check if the previous row (“2019-01-01 00:01:00”) is not equal to 1. This removes consecutive 1 of the sum.

JavaScript

Using your code:

JavaScript

Check:

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement