这个怎么样:
In [81]: bg = df.groupby(['x1', 'x2'], as_index=False)['x3'].agg({'my_sum':np.sum, 'my_mean':np.mean}) In [82]: print bg x1 x2 my_sum my_mean 0 a True 2 1 1 b False 1 1 2 b True 1 1