
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python Pandas - Check elementwise if the Intervals in the IntervalIndex contain the value
To check elementwise if the Intervals in the IntervalIndex contain the value, use the IntervalIndex. contains() method in Pandas.
At first, import the required libraries −
import pandas as pd
Create IntervalIndex −
interval = pd.IntervalIndex.from_tuples([(10, 20), (15, 25)])
Display the interval −
print("IntervalIndex...\n",interval)
Check if the interval contains a specific value −
print("\nDoes the interval contain a specific value?\n",interval.contains(13))
Example
Following is the code −
import pandas as pd # Create IntervalIndex interval = pd.IntervalIndex.from_tuples([(10, 20), (15, 25)]) # Display the interval print("IntervalIndex...\n",interval) # Display the interval length print("\nIntervalIndex length...\n",interval.length) # Check if the interval contains a specific value print("\nDoes the interval contain a specific value?\n",interval.contains(13))
Output
This will produce the following output −
IntervalIndex... IntervalIndex([(10, 20], (15, 25]], dtype='interval[int64, right]') IntervalIndex length... Int64Index([10, 10], dtype='int64') Does the interval contain a specific value? [ True False]
- Related Articles
- Check elementwise if the Intervals in the IntervalIndex contain the value in Python Pandas
- Python Pandas - Check elementwise if the Intervals contain the value
- Python Pandas - Check if the IntervalIndex has overlapping intervals
- Python Pandas IntervalIndex - Check if Intervals that share closed endpoints overlap
- Check elementwise if an Interval overlaps the values in the IntervalArray in Python Pandas
- Python Pandas - Check if the Intervals in the IntervalArray is empty
- Python Pandas IntervalIndex - Check if Intervals that only have an open endpoint in common overlap or not
- Python Pandas - Check whether the IntervalIndex intervals are closed on the left-side, right-side, both or neither
- Python Pandas IntervalIndex - Get the locations of all the relevant interval if a label is in several intervals
- Python Pandas - Check elementwise if an Interval overlaps the values in the IntervalArray created from an array of splits
- Python Pandas - Get the midpoint from the IntervalIndex
- Python Pandas - Get the length from the IntervalIndex
- Python Pandas - Get the left bound for the IntervalIndex
- Python Pandas - Get the right bound for the IntervalIndex
- Python Pandas IntervalIndex - Check if an interval that contains points is empty or not

Advertisements