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 this with the following code, which moves the Sector and Symbol values into a MultiIndex:
![](https://static.packt-cdn.com/products/9781787123137/graphics/assets/a692d34f-3544-4d2d-8931-9934eb7600b6.png)
The .index property now shows that the index...