groupby sum format to 2 dif code example Example: two groupby pandas In [8]: grouped = df.groupby('A') In [9]: grouped = df.groupby(['A', 'B'])