Shahjahan
Shahjahan

Reputation: 239

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

Below The image is a demo dataset

enter image description here

The Desired Result is like this, what pandas functions should I use here enter image description here

Please Read the headings in Image 2 to get a better understanding of my question

Upvotes: 0

Views: 52

Answers (1)

Vishnudev Krishnadas
Vishnudev Krishnadas

Reputation: 10970

Use groupby with aggregation

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

Upvotes: 2

Related Questions