I have a column on time and a column with binary data. every time the binary number changes from 1 to 0, that's 1 cycle. i'd like to add up the number of cycles per 1.5 second.
something like
first 1.5s - 1,0,1,0 -> 2 cycles
second 1.5s - 1,0 -> 1 cycle
third 1.5s - 1,0,1,0,1,0 -> 3 cycles.
thank you!!
Assuming your time is equi-distant, so 1.5s are always e.g. 3 rows, you can easily do that in a loop:
Otherwise (not equi-distant), you need to:
df.groupby(pd.Grouper(freq='1.5s')).sum()
, withpd
being pandas