If you know you always want to aggregate over the first two levels, then this is pretty easy:
In [27]: data.groupby(level=[0, 1]).sum()
Out[27]:
A B 277
b 37
a B 159
b 16
dtype: int64
If you know you always want to aggregate over the first two levels, then this is pretty easy:
In [27]: data.groupby(level=[0, 1]).sum()
Out[27]:
A B 277
b 37
a B 159
b 16
dtype: int64