 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Pandas - Return vector of label values using integer position of the level in the MultiIndex
To return vector of label values using integer position of the level in the MultiIndex, use the MultiIndex.get_level_values() method in Pandas. Set the level as an argument.
At first, import the required libraries −
import pandas as pd
MultiIndex is a multi-level, or hierarchical, index object for pandas objects −
multiIndex = pd.MultiIndex.from_arrays([list('pqrrss'), list('strvwx')],names=['One', 'Two'])  Display the MultiIndex −
print("The MultiIndex...\n",multiIndex) Get level values at level 0 −
print("\nLevel values at level 0...\n",multiIndex.get_level_values(0))  Example
Following is the code −
import pandas as pd # MultiIndex is a multi-level, or hierarchical, index object for pandas objects multiIndex = pd.MultiIndex.from_arrays([list('pqrrss'), list('strvwx')],names=['One', 'Two']) # display the MultiIndex print("The MultiIndex...\n",multiIndex) # get the levels in MultiIndex print("\nThe levels in MultiIndex...\n",multiIndex.levels) # get level values at level 0 print("\nLevel values at level 0...\n",multiIndex.get_level_values(0))  Output
This will produce the following output −
The MultiIndex... MultiIndex([('p', 's'),             ('q', 't'),             ('r', 'r'),             ('r', 'v'), ('s', 'w'), ('s', 'x')], names=['One', 'Two']) The levels in MultiIndex... [['p', 'q', 'r', 's'], ['r', 's', 't', 'v', 'w', 'x']] Level values at level 0... Index(['p', 'q', 'r', 'r', 's', 's'], dtype='object', name='One')Advertisements
 