- 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 - 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 Questions & Answers
- 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
- Check if any interval completely overlaps the other in Python
- Python Pandas - Construct an IntervalArray from an array-like of tuples
- 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 midpoint of each Interval in the IntervalArray as an Index
- Python Pandas - Check if an element belongs to an Interval
- Python Pandas - Check elementwise if the Intervals contain the value

Advertisements