
- Python 3 Basic Tutorial
- Python 3 - Home
- What is New in Python 3
- Python 3 - Overview
- Python 3 - Environment Setup
- Python 3 - Basic Syntax
- Python 3 - Variable Types
- Python 3 - Basic Operators
- Python 3 - Decision Making
- Python 3 - Loops
- Python 3 - Numbers
- Python 3 - Strings
- Python 3 - Lists
- Python 3 - Tuples
- Python 3 - Dictionary
- Python 3 - Date & Time
- Python 3 - Functions
- Python 3 - Modules
- Python 3 - Files I/O
- Python 3 - Exceptions
Check elementwise if an Interval overlaps the values in the IntervalArray in Python Pandas
To check elementwise if an Interval overlaps the values in the IntervalArray, use the overlaps() method in Pandas.
At first, import the required libraries −
import pandas as pd
Two intervals overlap if they share a common point, including closed endpoints. Intervals that only have an open endpoint in common do not overlap. Create an IntervalArray −
intervals = pd.arrays.IntervalArray.from_tuples([(10, 20), (15, 35)])
Display the IntervalArray −
print("IntervalArray...\n",intervals)
Check elementwise if an Interval overlaps the values in the IntervalArray −
print("\nDoes interval overlaps values in the IntervalArray...\n",intervals.overlaps(pd.Interval(12, 30)))
Example
Following is the code −
import pandas as pd # Two intervals overlap if they share a common point, including closed endpoints. Intervals # that only have an open endpoint in common do not overlap # Create an IntervalArray intervals = pd.arrays.IntervalArray.from_tuples([(10, 20), (15, 35)]) # Display the IntervalArray print("IntervalArray...\n",intervals) # Display the interval length print("\nInterval length...\n",intervals.length) # Check elementwise if an Interval overlaps the values in the IntervalArray print("\nDoes interval overlaps values in the IntervalArray...\n",intervals.overlaps(pd.Interval(12, 30)))
Output
This will produce the following output −
IntervalArray... <IntervalArray> [(10, 20], (15, 35]] Length: 2, dtype: interval[int64, right] Interval length... Int64Index([10, 20], dtype='int64') Does interval overlaps values in the IntervalArray... [ True True]
- Related Articles
- Python Pandas - Check elementwise if an Interval overlaps the values in the IntervalArray created from an array of splits
- Check if any interval completely overlaps the other in Python
- Python Pandas - Check elementwise if the Intervals contain the value
- Python Pandas - Check if the Intervals in the IntervalArray is empty
- Python Pandas - Check elementwise if the Intervals in the IntervalIndex contain the value
- Python Pandas - Return the midpoint of each Interval in the IntervalArray as an Index
- Check elementwise if the Intervals in the IntervalIndex contain the value in Python Pandas
- Python Pandas - Check if an interval is empty
- python Pandas - Return the left endpoints of each Interval in the IntervalArray as an Index
- Python Pandas - Return the right endpoints of each Interval in the IntervalArray as an Index
- Python Pandas - Check if the Pandas Index holds Interval objects
- Python Pandas - Return an Index with entries denoting the length of each Interval in the IntervalArray
- Python Pandas - Check if an element belongs to an Interval
- Python Pandas IntervalIndex - Check if an interval with missing values is empty or not
- Python Pandas - Check if an Interval is closed on the left side

Advertisements