How to merge column data of the same value and sum

2019-07-16 03:47发布

How can I merge column data of the same value and sum its specific data (in this case based of the DATE column)

For Example: df includes:

78      79      80      DATE
8.99    7.99    6.99    201107
3.5     2.5     1.5     201107
5.48    4.48    3.48    201108
4.04    3.04    2.04    201108
5.03    4.03    3.03    201108

What I would like is:

78      79      80      DATE
12.49   10.49   8.49    201107
14.55   11.55   8.55    201108

What is the simplest way of achieving this?

1条回答
对你真心纯属浪费
2楼-- · 2019-07-16 04:07

You can groupby on 'DATE' column and then call sum:

In [202]:
df.groupby('DATE', as_index=False).sum()

Out[202]:
     DATE     78     79    80
0  201107  12.49  10.49  8.49
1  201108  14.55  11.55  8.55
查看更多
登录 后发表回答