pandas:
df['data'].groupby((df['cond'] != df['cond'].shift()).cumsum()).agg(['count', 'mean'])[lambda x: x['count']==x['count'].max()]
Out:
count mean
cond
3 3 1.466667
0.18.0, :
res = df['data'].groupby((df['cond'] != df['cond'].shift()).cumsum()).agg(['count', 'mean'])
res[res['count'] == res['count'].max()]
Out:
count mean
cond
3 3 1.466667
:
, df['cond'] != df['cond'].shift() :
df['cond'] != df['cond'].shift()
Out:
0 True
1 True
2 True
3 False
4 False
5 True
6 True
Name: cond, dtype: bool
, False, , . , , () :
(df['cond'] != df['cond'].shift()).cumsum()
Out:
0 1
1 2
2 3
3 3
4 3
5 4
6 5
Name: cond, dtype: int32
groupby ( , ), . .agg(['count', 'mean'] , , .
, False . True, :
((df['cond'] != df['cond'].shift()) | (df['cond'] != True)).cumsum()
False, True, " OR not True". , :
df['data'].groupby(((df['cond'] != df['cond'].shift()) | (df['cond'] != True)).cumsum()).agg(['count', 'mean'])[lambda x: x['count']==x['count'].max()]