the first statement calculates the mean price for all transactions by user_typewhile the second one counts the number of transactions per week though these calculations are helpfulgrouping data based on attributes helps us get better understanding of it the groupby(function helps us perform the sameas shown in the following snippet print(df groupby(['user_class'])['quantity_purchased'sum()this statement generates tabular output representing sum of quantities purchased by each user_class the output is generated is as follows user_class existing loyal_existing new namequantity_purchaseddtypeint the groupby(function is powerful interface that allows us to perform complex groupings and aggregations in the previous example we grouped only on single attribute and performed single aggregation ( sumwith groupby(we can perform multi-attribute groupings and apply multiple aggregations across attributes the following snippet showcases three variants of groupby(usage and their corresponding outputs variant- multiple aggregations on single attribute df groupby(['user_class'])['quantity_purchased'agg([np sumnp meannp count_nonzero]variant- different aggregation functions for each attribute df groupby(['user_class','user_type']agg({'price':np mean'quantity_purchased':np max}variant- df groupby(['user_class','user_type']agg({'price':{'total_price':np sum'mean_price':np mean'variance_price':np std'count':np count_nonzero}'quantity_purchased':np sum}the three different variants can be explained as follows variant here we apply three different aggregations on quantity purchased which is grouped by user_class (see figure - figure - groupby with multiple aggregations on single attribute