Exercise

Computing multiple aggregates of multiple columns

The .agg() method can be used with a tuple or list of aggregations as input. When applying multiple aggregations on multiple columns, the aggregated DataFrame has a multi-level column index.

In this exercise, you're going to group passengers on the Titanic by 'pclass' and aggregate the 'age' and
'fare' columns by the functions 'max' and 'median'. You'll then use multi-level selection
to find the oldest passenger per class and the median fare price per class.

The DataFrame has been pre-loaded as titanic.

Instructions

100 XP

Group titanic by 'pclass' and save the result as by_class.

Select the 'age' and 'fare' columns from by_class and save the result as by_class_sub.

Aggregate by_class_sub using 'max' and 'median'. You'll have to pass 'max' and 'median' in the form of a list to .agg().

Use .loc[] to print all of the rows and the column specification ('age','max'). This has been done for you.

Use .loc[] to print all of the rows and the column specification ('fare','median').