How to groupby based on two columns in pandas?

A similar question might have been asked before, but I couldn’t find the exact one fitting to my problem. I want to group by a dataframe based on two columns. For exmaple to make this

id product quantity
1  A       2
1  A       3
1  B       2
2  A       1
2  B       1
3  B       2
3  B       1

Into this:

id product quantity
1  A       5
1  B       2
2  A       1
2  B       1
3  B       3

Meaning that summation on “quantity” column for same “id” and same “product”.

Leave a Comment

tech