Python Pandas – Check whether two Interval objects that share closed endpoints overlap
In this article, we will cover how to check whether two intervals with sharing endpoint overlap or not. For this, we use the Interval class from pandas and the overlaps() method for all the interval-related operations.
- other : interval object. Check for an overlap using this interval.
Returns : bool . returns true if two intervals overlap. else it returns false.
Import all the required libraries.
Create the two Intervals that share closed endpoints
pd.Interval(1,5, closed =both") pd.Interval(5,10, closed="both")
Check whether the intervals overlap or not using the overlaps() method. It returns a bool.
IsOverlap = Interval1.overlaps(Interval2)
Example 1: Create and then check if two intervals that share closed endpoints overlap.
Example 2: Create and then check if an array of intervals that share closed endpoints overlap a given interval [3,16].
Please Login to comment...