- 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 an Interval overlaps the values in the IntervalArray created from an array of splits

To check elementwise if an Interval overlaps the values in the IntervalArray created from an array of splits, use the **array.overlaps()** method.

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. Construct a new IntervalArray from an array-like of splits −

array = pd.arrays.IntervalArray.from_breaks([0, 1, 2, 3, 4, 5])

Display the intervals −

print("Our IntervalArray...\n",array)

Check for overlap −

print("\nDoes the Interval overlaps the values in the IntervalArray", array.overlaps(pd.Interval(2.5, 3.2)))

## 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. # Construct a new IntervalArray from an array-like of splits array = pd.arrays.IntervalArray.from_breaks([0, 1, 2, 3, 4, 5]) # Display the IntervalArray print("Our IntervalArray...\n",array) # check for overlap print("\nDoes the Interval overlaps the values in the IntervalArray", array.overlaps(pd.Interval(2.5, 3.2)))

## Output

This will produce the following code −

Our IntervalArray... <IntervalArray> [(0, 1], (1, 2], (2, 3], (3, 4], (4, 5]] Length: 5, dtype: interval[int64, right] Does the Interval overlaps the values in the IntervalArray [False False True True False]

- Related Articles
- Check elementwise if an Interval overlaps the values in the IntervalArray in Python Pandas
- Python Pandas - Construct an IntervalArray from an array of splits
- Python Pandas - Construct an IntervalArray from an array of splits and return the left endpoints of each interval
- Python Pandas - Construct an IntervalArray from an array of splits and return the right endpoints of each interval
- Python Pandas - Create an IntervalArray from an array of splits and check the intervals are closed on the left or right-side, both or neither
- Python Pandas - Construct an IntervalArray from an array-like of tuples and return the right endpoints of each Interval
- Python Pandas - Construct an IntervalArray from an array-like of tuples and return the left endpoints of each Interval
- Python Pandas - Construct an IntervalArray from an array-like of tuples
- Check if any interval completely overlaps the other in Python
- Python Pandas - Return the midpoint of each Interval in the IntervalArray as an Index
- Python Pandas - Check if an interval is empty if closed from the left side
- Python Pandas - Check if an interval is empty if closed from the both sides
- 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

Advertisements