Skip to content
Advertisement

pandas: combine size and sum in a single groupby?

I have a dataframe of houses, one row per house, that looks like this:

JavaScript
JavaScript

And I want to end up with a table that looks like this:

JavaScript

Currently I’m doing two separate groupby calls, and then joining them together:

JavaScript

Is there a way I could do this with a single groupby?

Advertisement

Answer

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement