Hierarchical indexing is a feature of pandas that allows the combined use of two or more indexes per row. Each of the indexes in a hierarchical index is referred to as a level. The specification of multiple levels in an index allows for efficient selection of different subsets of data using different combinations of the values at each level. Technically, a pandas index that has multiple levels of hierarchy is referred to as a MultiIndex.
The following code demonstrates creating and accessing data via a MultiIndex using the sp500 data. Suppose we want to organize this data by both the values of Sector and Symbol so that we can efficiently look up data based on a combination of values from both variables. We can accomplish ...