March 2020
Beginner to intermediate
352 pages
8h 40m
English
Don't you think the output dataframe would be more informative if we could rename the column name with the operation we performed in that column or group?
We can perform aggregation in each group and rename the columns according to the operation performed. This is useful for understanding the output dataset:
df.groupby( ["body-style","drive-wheels"]).agg( # Get max of the price column for each group max_price=('price', max), # Get min of the price column for each group min_price=('price', min), # Get sum of the price column for each group total_price=('price', 'mean') )
The output of the preceding code is as follows:
As shown in the preceding screenshot, we only selected two categories: body-style and ...
Read now
Unlock full access