I have a pandas dataframe with a datetime index along with multiple columns of 1 an 0's. I wish to clump those 1's and 0's up to figure out how many are in a sequence. I then wish to determine the minimum, mean, and maximum time the clumps were in each column using the datetime index. I only need the 1's counted since in essence, they are the "on" values in this case. If there is only one 1, then the time from that 1 to the next row will be the timeframe.
So far I have seen the first part done this way from this post Counting cons values and adding them
y * (y.groupby((y != y.shift()).cumsum()).cumcount() + 1)
The index is "year-month-day hour:minute:second"
An example of the Dataframe is as follows.
col1 col2
datetime
2021-05-24 00:09:22 1 0
2021-05-24 00:09:24 1 0
2021-05-24 00:09:25 0 1
2021-05-24 00:09:26 1 0
2021-05-24 00:09:27 0 0
With a wanted output like this for a column in seconds or minutes. The output has to use the datetime index rather of just calculating the consecutive values and multiplying the time since the datetime is not consistent.
col1 col2
min 1 1
max 3 1
mean 2 1