Search⌘ K

More Aggregations

Explore how to use pandas' groupby transform to perform aggregations that keep original row indexes, and apply filtering on grouped data while retaining the original structure. Understand how to efficiently count responses by category and filter groups based on aggregated values to handle data flexibly.

Aggregations while keeping rows

Let’s assume we’re still looking at the JetBrains dataset, and we want to add a new column, the count of responses from a country. One way to do that would be to create a pivot table (or groupby) of the count of responses for each country and then merge that data back into the original DataFrame. However, if we use the transform method following groupby, we get the aggregation, but they’re not collapsed. The result is in terms of the original index.

So, one of the reasons we should gravitate toward ...