简体   繁体   中英

how to sum values of third column where col1 col2 have duplicates in pandas

Below The image is a demo dataset

在此处输入图像描述

The Desired Result is like this, what pandas functions should I use here在此处输入图像描述

Use groupby with aggregation

df.groupby(['col1', 'col2']).agg({'col3': ['count', 'sum']})

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