I have a dataframe
import pandas as pd
import numpy as np
v1=list(np.random.rand(30))
v2=list(np.random.rand(30))
mydf=pd.DataFrame(data=zip(v1,v2),columns=['var1','var2'])
then I apply some boolean conditions on some variables
mydf['cond1']=mydf['var1']>0.2
mydf['cond2']=mydf['var1']>0.8
mydf['cond1']=
0 False
1 True
2 True
3 False
4 False
5 True
6 False
....
I would like to group in blocks where 'cond1' (or 'cond2') is True, and for each group store:
the value of the group: True/False
the index of the start, and of the end, of the block: e.g. 1,2 5,5
the 2 values of
var2
at index of the start, and of the end,all the values of
var1
between the index of the start, and of the end, as an iterable (list of np.array)
this is one example of returned values:
summary=
'Start' 'End' 'Start_var2' 'End_var2' 'Value' 'var1'
1 2 0.3217381 0.454543 True [0.25,0.26]