Python (Pandas) Add subtotal on each lvl of multiindex dataframe

后端 未结 2 704
遇见更好的自我
遇见更好的自我 2020-12-08 06:02

Assuming I have the following dataframe:

a       b       c      Sce1     Sce2    Sce3    Sce4    Sce5    Sc6
Animal  Ground  Dog    0.0      0.9     0.5             


        
2条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-08 06:35

    you need to do two group by to get subtotals at every level of aggregation. Then add those back in to the initial DF. Here's a related question.

提交回复
热议问题