Let's explore how the groupby function works for hierarchically indexed data.
To start with, we can assign two indices to the sample sales data, as shown:
multiindex_df = sales_data.set_index(["ShipMode", "Category"])multiindex_df.head()
The following will be the output:
Grouping by an index can be done by specifying either the level number or the index name:
multiindex_df.groupby(level = 0).sum()
The following will be the output:
The level parameter ...