From the course: Python Data Visualization: Create Impactful Visuals, Animations, and Dashboards by Pearson
Unlock this course with a free trial
Join today to access over 25,200 courses taught by industry experts.
GroupBy and Pivot tables - Python Tutorial
From the course: Python Data Visualization: Create Impactful Visuals, Animations, and Dashboards by Pearson
GroupBy and Pivot tables
Very often, we need to compute statistics or aggregate our data in a different way. We already saw how we could do that using map, transform, and apply functions. There's also the group by function that gives us a little bit more flexibility about how we can do this. GroupBy essentially allows us to group values of a column or a dataframe based on some value of that column, and then apply functions to the groups that are generated this way. So to give you an example, if you have, let's say, a dataframe on different features of, let's say, car models, you could do a GroupBy brand and then compute statistics for each brand. price, average number of units sold, etc. based on the brand that is one of the columns of your data frame. There are many functions that are supported with GroupBy, so the usual summary statistics, max, min, mean, median transform, sum, commutative sum, product, commutative product, etc. You can of course also call transform and apply functions to compute…