In Python Pandas, the MultiIndex object is the hierarchical analogue of the standard Index object which typically stores the axis labels in pandas objects. You can consider that MultiIndex is an array of unique tuples.
pandas.MultiIndex.from_arrays() method
The pandas.MultiIndex.from_arrays() method is used to create a MultiIndex, and the names parameter is used to set names of each of the index levels. This method accepts two parameters arrays and names.
First, we have to import the pandas library:
import pandas as pd
Consider the below examples –
Example 1:
Output:
The MultiIndex... MultiIndex([(101, 'Shivang'), (102, 'Radib'), (103, 'Monika')], names=['ids', 'student']) The names of levels in Multi-index... ['ids', 'student']Example 2:
Output:
The MultiIndex... MultiIndex([('New Delhi', 'New York'), ( 'Mumbai', 'Los Angeles'), ( 'Banglore', 'Chicago'), ( 'Kolkata', 'Houston')], names=['india_cities', 'usa_cities']) The names of levels in Multi-index... ['india_cities', 'usa_cities']need an explanation for this answer? contact us directly to get an explanation for this answer