How to add a sum column onto a multiindex DataFrame without messing up the table?

I have a DataFrame looks something like the following

Info1info2
WorldASIAJP1004
KR2003
NAUSA3002
CA4001

Is it possible to make a sum() column by index level 1 without messing up by index?

Desired output:

Info1info2info1_sum_country
WorldASIAJP1004300
KR2003
NAUSA3002700
CA4001

​

Posted May 4, 2022, 1:40 AM UTC

10
Loading comments…