ser = A.loc[mask, col2]
result.append((ser.mean(), ser.std(), mask2.sum()))
index = pd.MultiIndex.from_product([pairs, [1, 2]], names=['pair', 'cond'])
df = pd.DataFrame(result, index=index, columns=['mean', 'sum', 'count'])
print(df)
How to apply Pandas Groupby with multiple conditions for split and apply multiple calculations?