I have DataFrame in Python Pandas like below:
Data types:
- MONTH_NR - numeric
- MONTH_NAME - object
- VALUE - numeric
MONTH_NR | MONTH_NAME | VALUE |
---|---|---|
1 | JANUARY | 10 |
2 | FEBRYARY | 20 |
3 | MARCH | 15 |
4 | APRIL | 10 |
5 | MAY | 11 |
6 | JUN | 100 |
7 | JULY | 200 |
8 | AUGUST | 12 |
9 | SEPTEMBER | 20 |
10 | OCTOBER | 50 |
11 | NOVEMBER | 30 |
12 | DECEMBER | 50 |
And I need to add 3 new ROWS where will be:
- sum of values from column "VALUE" after 6 month (from 1 till 6)
- sum of values from column "VALUE" after 12 month (from 7 till 12)
- sum of values from column "VALUE" after 12 month (from 1 till 12)
So as a result I need somethin like below:
MONTH_NR | MONTH_NAME | VALUE
---------|-------------|---------
1 | JANUARY | 10
2 | FEBRYARY | 20
3 | MARCH | 15
4 | APRIL | 10
5 | MAY | 11
6 | JUN | 100
SUM_AFTER_1_6| | 166
7 | JULY | 200
8 | AUGUST | 12
9 | SEPTEMBER | 20
10 | OCTOBER | 50
11 | NOVEMBER | 30
12 | DECEMBER | 50
SUM_AFTER_7_12| | 362
SUM_ALL | | 528
How can I do that in Python Pandas ?
1条答案
按热度按时间wpx232ag1#
建议的方法: