Selecting a subset of columns

To form groups based on multiple categories, we can simply specify the column names in the groupby() function. Grouping will be done simultaneously with the first category, the second category, and so on. 

Let's groupby using two categories, body-style and drive wheels, as follows: 

double_grouping = df.groupby(["body-style","drive-wheels"])
double_grouping.first()

The output of the preceding code is as follows:

Not only can we group the dataset with specific criteria, but we can also perform arithmetic operations directly on the whole group at the same time and print the output as a series or dataframe. There are functions such as max(), min(), mean(), first(), and last() that can be directly applied to the GroupBy object in order to obtain summary statistics for each group.

In the next section, we are going to discuss these functions one by one. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.84.169