I have some acceleration data for which I am trying to count the length of sequences given a set of conditions. In this case I want to count the length of a sequence when the acceleration moves > 2.78 and then drops back below 0.
An example would be
[-1.1, -1, 0, 1.2, 1.8, 2, 2.88, 2.86, 2.53, 1.98, 1.21, 0.89, 0.11, -0.21]
The return result here would be a count of 7 (2.88, 2.86, 2.53, 1.98, 1.21, 0.89, 0.11)
I have done this previously to identify the length of sequences strictly >2.78 using the following code. I need to build on this to provide lengths using 0 as the endpoint.
def get_Accel_lengths( array ) :
s = ''.join( ['0' if i < 2.78 else '1' for i in resultsQ4['AccelInt']] )
parts = s.split('0')
return [len(p) for p in parts if len(p) > 0]
Q4Accel = get_Accel_lengths(resultsQ4['AccelInt'])
Q4Accel = pd.DataFrame(Q4Accel)
Q4Accel
Using the above example, the result for this code would be 2 (2.88, 2.86)