2

I'm trying to group by multiple column and aggregate on multiple as well. In sql it would give that:

SELECT A, B, C, COUNT(1), SUM(E), SUM(F) GROUP BY A, B, C

So far i came up with this but it only aggregate on one column:

df.groupby(['A','B','C')['E'].sum()

1 Answer 1

2

It seems you need aggregate:

print (df.groupby(['A','B','C']).agg({'A':'size', 'E':'sum','F':'sum'}))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.