Hierarchical Indexes
Hierarchical indexing means you can have
multiple indexes on an array, for example: a bit like a merged cell in Excel, right?
Select a subset of the data
based on the index to select a subset of the data from the other layer:
Select data in the same way as the index in the layer:
Multi-index series conversion to Dataframe hierarchical indexes play an important role in data reshaping and grouping, for example, the hierarchical index data above can be converted to a dataframe:
For a dataframe, both the horizontal and vertical axes can have hierarchical indexes, for example:
Rearrange
ranking order
The Swaplevel () function can exchange two levels of data
based on the index exchange , for example:
Sort by
index the Sortlevel () function sorts the data based on a single level of value, for example: Sort by row by first level:
Sort by row by the second level:
Sort by column by first level:
Summary statistics by level
Multi-level indexed data can be aggregated at the individual level, for example:
Using Python for data analysis (one) Pandas Basics: Hierarchical indexing