-
Book Overview & Buying
-
Table Of Contents
Python Data Analysis - Fourth Edition
By :
Grouping is one of the data summarization operations that is used to group a similar item and compute the aggregate value for each group. The concept of grouping is taken from a relational database or SQL. In pandas, DataFrames offers groupby() method to perform grouping operations and perform aggregate operations on groups like min, max, mean, count, and sum. The core of grouping operation is the split-apply-combine technique. The data is first divided into groups, then aggregate operation (mean, min, max, count, total, etc.) is applied to each group, and results from each group are combined to frame the final output:
# Group By DataFrame on the basis of Continent column
df.groupby('Continent').mean()
This results in the following output:

Let's now group the DataFrames based on literacy rates as well:
# Group By DataFrame on the basis of continent and select adult literacy rate(%)
df.groupby('Continent').mean()[&apos...