简体   繁体   中英

Sum of specific rows in pandas dataframe

I have a table like this:

在此处输入图片说明

I want to sum actual values of same segment,same group, same date like this:

在此处输入图片说明

If I use pd.groupby, it don't seem like above table.

I would be very grateful if someone could help. Thanks.

df.groupby(["segment", "group", "date"]).sum().reset_index()

# output
  segment group    date  actual
0       A     a  21-Jun       8
1       A     b  21-Jul       7
2       A     c  21-Aug       8
3       B     e  21-Sep      10
4       C     d  21-Nov       7
5       C     f  22-Jan       7

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM