

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
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 - Get integer location for requested label
To get the integer location for requested label in Pandas, use the index.get_loc() method. At first, import the required libraries −
import pandas as pd
Create Pandas index object −
index = pd.Index(list('pqrstuvwxyz'))
Display the Pandas index −
print("Pandas Index...\n",index)
Get integer location from the given index −
print("\nDisplay integer location from given index...\n",index.get_loc('w')) print("\nDisplay integer location from given index...\n",index.get_loc('z'))
Example
Following is the code −
import pandas as pd # create Pandas index object index = pd.Index(list('pqrstuvwxyz')) # Display the Pandas index print("Pandas Index...\n",index) # Return the number of elements in the Index print("\nNumber of elements in the index...\n",index.size) # get integer location from the given index print("\nDisplay integer location from given index...\n",index.get_loc('w')) print("\nDisplay integer location from given index...\n",index.get_loc('z'))
Output
This will produce the following output −
Pandas Index... Index(['p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'], dtype='object') Number of elements in the index... 11 Display integer location from given index... 7 Display integer location from given index... 10
- Related Questions & Answers
- Python Pandas IntervalIndex - Get integer location for requested label
- Python Pandas - Get integer location for requested label and find the previous index value if no exact match
- Python Pandas - Get integer location for requested label and find the nearest index value if no exact match
- Python Pandas - Get location and sliced index for requested label/ level in a MultiIndex
- Python Pandas - Get location and sliced index for requested label/ level but do not drop the level
- Python Pandas - Get the codes (location of each label) in MultiIndex
- Python Pandas - Return vector of label values for requested level in a MultiIndex
- Python Pandas - Get location for a label or a tuple of labels in a MultiIndex
- Python Pandas - Get location for a sequence of labels in a MultiIndex
- Python Pandas - How to select rows from a DataFrame by integer location
- Python Pandas - Return MultiIndex with requested level removed
- Python Pandas - Get the seconds from Timedelta object using integer input
- Python Pandas - Get the Integer number of levels in this MultiIndex
- Python Pandas - Return vector of label values using integer position of the level in the MultiIndex
- Python Pandas - Return MultiIndex with requested level removed using the level name
Advertisements