

- 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 IntervalIndex - Get integer location for requested label
To get integer location for requested label, use the get_loc() method in Pandas. At first, import the required libraries −
import pandas as pd
Create two Interval objects. Closed intervals set using the "closed" parameter with value "both" −
interval1 = pd.Interval(50, 75) interval2 = pd.Interval(75, 90)
Create IntervalIndex from the two intervals −
index = pd.IntervalIndex([interval1, interval2])
Get integer location for requested label −
print("\nInteger location for requested label...\n",index.get_loc(75))
Example
Following is the code −
import pandas as pd # Create two Interval objects # Closed intervals set using the "closed" parameter with value "both" interval1 = pd.Interval(50, 75) interval2 = pd.Interval(75, 90) # display the intervals print("Interval1...\n",interval1) print("Interval2...\n",interval2) # Create IntervalIndex from the two intervals index = pd.IntervalIndex([interval1, interval2]) # Get integer location for requested label print("\nInteger location for requested label...\n",index.get_loc(75))
Output
This will produce the following output −
Interval1... (50, 75] Interval2... (75, 90] Integer location for requested label... 0
- Related Questions & Answers
- Python Pandas - 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 left bound for the IntervalIndex
- Python Pandas - Get the right bound for the IntervalIndex
- 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 the midpoint from the IntervalIndex
- Python Pandas - Get the length from the IntervalIndex
- Python Pandas - Create an IntervalIndex
- Python Pandas IntervalIndex - Get the locations of all the relevant interval if a label is in several intervals
- Python Pandas - Get location for a sequence of labels in a MultiIndex
Advertisements