- 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 whether two Interval objects overlap

To check whether two Interval objects overlap, use the **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. Create two Interval objects

interval1 = pd.Interval(10, 30) interval2 = pd.Interval(25, 35)

Display the intervals

print("Interval1...

",interval1) print("Interval2...

",interval2)

Check whether both the interval objects overlap

print("

Do both the interval objects overlap?

",interval1.overlaps(interval2))

## 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 two Interval objects interval1 = pd.Interval(10, 30) interval2 = pd.Interval(25, 35) # display the intervals print("Interval1...

",interval1) print("Interval2...

",interval2) # display the length of both Interval1 and Interval2 objects print("

Interval1 object length = ",interval1.length) print("

Interval2 object length = ",interval2.length) # check whether both the interval objects overlap print("

Do both the interval objects overlap?

",interval1.overlaps(interval2))

## Output

This will produce the following code

Interval1... (10, 30] Interval2... (25, 35] Interval1 object length = 20 Interval2 object length = 10 Do both the interval objects overlap? True

- Related Questions & Answers
- Python Pandas - Check whether two Interval objects that share closed endpoints overlap
- Python Pandas - Check whether two Interval objects that share an open endpoint overlap
- Python Pandas - Check if the Pandas Index holds Interval objects
- Python Pandas - Check whether the two Index objects have similar object attributes and types
- Python Pandas - Check if an interval is empty
- Python Pandas IntervalIndex - Check if Intervals that share closed endpoints overlap
- Python Pandas IntervalArray - Check Intervals that share closed endpoints overlap or not
- Python Pandas - Check whether the interval is closed on the left-side, right-side, both or neither
- Python Pandas - Check if an element belongs to an Interval
- Python Pandas - Form the intersection of two Index objects
- Python Pandas - Form the Union of two Index objects
- Python Pandas - Determine if two Index objects are equal
- Python Pandas - Check if an interval set as open is empty
- Python Pandas - Compute the symmetric difference of two Index objects
- Python Pandas - Check if an Interval is closed on the left side

Advertisements