arr = np.concatenate(([False], df.cond.values, [False]))
start = np.nonzero(arr[1:] > arr[:-1])[0]
stop = np.nonzero(arr[1:] < arr[:-1])[0]
maxID = (stop - start).argmax()
out = df.data.iloc[start[maxID]:stop[maxID]].mean()
Determine mean value of ‘data’ where the highest number of CONTINUOUS cond=True