Python Pandas – Check whether two Interval objects overlap
The panda’s Interval.overlaps() method is used to Check whether Interval objects are overlapping. Two intervals, including closed ends, overlap if they share the same point. Intervals that share only an open endpoint do not intersect.
other : interval object. Check for an overlap using this interval.
Returns : bool . returns true if two intervals overlap. else it returns false.
Pandas package is imported and two intervals are created using the pd.Interval() method. pd.Interval() method creates an object interval. pandas.Interval.overlaps() method is used to check whether the two intervals overlap and the result is returned.
first interval is :(5, 15] second interval is :(10, 25] do the intervals overlap ? : yes
when we don’t explicitly specify the closed parameter by default it’s ‘right’. the intervals have only one endpoint in common so they do not overlap.
first interval is :(0, 10] second interval is :(10, 20] do the intervals overlap ? : no
Here both intervals share closed endpoints so they overlap. The closed parameter is ‘both’ for both intervals.
first interval is :[0, 10] second interval is :[10, 20] do the intervals overlap ? : yes
Please Login to comment...