How to add a sum column onto a multiindex DataFrame without messing up the table?
I have a DataFrame looks something like the following
| Info1 | info2 | |||
|---|---|---|---|---|
| World | ASIA | JP | 100 | 4 |
| KR | 200 | 3 | ||
| NA | USA | 300 | 2 | |
| CA | 400 | 1 |
Is it possible to make a sum() column by index level 1 without messing up by index?
Desired output:
| Info1 | info2 | info1_sum_country | |||
|---|---|---|---|---|---|
| World | ASIA | JP | 100 | 4 | 300 |
| KR | 200 | 3 | |||
| NA | USA | 300 | 2 | 700 | |
| CA | 400 | 1 |
Posted May 4, 2022, 1:40 AM UTC
10