Я считаю, что вам нужно GroupBy.agg
с именованным агрегацией:
df['Time'] = pd.to_datetime(df['Time'])
m = df['flag'].eq(10)
g = m.ne(m.shift()).cumsum()[m]
df['count'] = g.map(g.value_counts())
df = df.groupby(df['Time'].dt.date).agg(group_start_time_1=('Time','first'),
group_end_time_1=('Time','last'),
count_change_to_10 =('count','nunique'),
minimum_duration_of_each_group_value_remains_10=('count', 'min'),
Maximum_duration_of_each_group_value_remains_10=('count', 'max'))
print (df)
group_start_time_1 group_end_time_1 count_change_to_10 \
Time
2019-02-14 2019-02-14 00:00:10 2019-02-14 00:00:32 1
2019-02-15 2019-02-15 00:00:37 2019-02-15 00:00:59 1
minimum_duration_of_each_group_value_remains_10 \
Time
2019-02-14 2.0
2019-02-15 3.0
Maximum_duration_of_each_group_value_remains_10
Time
2019-02-14 2.0
2019-02-15 3.0
РЕДАКТИРОВАТЬ: Решение для pandas <0,25 со словарем в <a href="http://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.GroupBy.agg.html" rel="nofollow noreferrer">GroupBy.agg
со словарем:
df['Time'] = pd.to_datetime(df['Time'])
m = df['flag'].eq(10)
#consecutive groups only by mask
g = m.ne(m.shift()).cumsum()[m]
#counter only matched values by mask
df['count'] = g.map(g.value_counts())
df = df.groupby(df['Time'].dt.date).agg({'Time':['first','last'],
'count':['nunique','min','max']})
df.columns = df.columns.map('_'.join)
d = {'Time_first':'group_start_time_1',
'Time_last':'group_end_time_1',
'count_nunique':'count_change_to_10',
'count_min':'minimum_duration_of_each_group_value_remains_10',
'count_max':'Maximum_duration_of_each_group_value_remains_10'}
cols = ['Maximum_duration_of_each_group_value_remains_10',
'Maximum_duration_of_each_group_value_remains_10']
df = df.rename(columns=d)
df[cols] = df[cols].astype(int)
df = df.reset_index()
print (df)
Time group_start_time_1 group_end_time_1 count_change_to_10 \
0 2019-02-14 2019-02-14 00:00:10 2019-02-14 00:00:32 1
1 2019-02-15 2019-02-15 00:00:37 2019-02-15 00:00:59 1
minimum_duration_of_each_group_value_remains_10 \
0 2.0
1 3.0
Maximum_duration_of_each_group_value_remains_10
0 2
1 3