每当我使用groupby时,我得到的结果如下:
df.groupby(by =['day','gender']).['total].sum()
输出:
gender day sum
male mon 56
tues 45
..
female mon 44
tues 25
...
我希望输出:
gender day sum
male mon 56
male tues 45
..
female mon 44
female tues 25
答案 0 :(得分:1)
try:
df.groupby(by=['day', 'gender'], as_index=False).['total'].sum()