Advanced Indexing 2
Learn how to use advanced indexing techniques to work effectively with MultiIndex DataFrames.
We'll cover the following
Overview
Having seen how to sort and select data from MultiIndex DataFrames, we now explore how the indexes can be modified.
The swaplevel()
and reorder_levels
There may be occasions when we want to modify the order of the indexes. We can utilize the swaplevel()
method to flip the order of two levels. We can pass either the level number or label name into the swaplevel()
method, because both are accepted and will give the same output.
Let's see how we can perform the level swapping either by level number (i.e., index position) with the following example:
Get hands-on with 1200+ tech skills courses.