Rearrange levels using level name in MultiIndex
The pandas.MultiIndex.reorder_levels() method is used to rearrange levels using level name in MultiIndex.
Syntax:
MultiIndex.reorder_levels(order)
The method accepts list representing a new level order that can be either list of int or list of str and return the MultiIndex.
To work with MultiIndex in Python Pandas, we need to import the pandas library. Below is the syntax,
import pandas as pd
Python code to rearrange levels using level name in MultiIndex
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer