- 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 IntervalArray - Check Intervals that share closed endpoints overlap or not

To check Intervals that share closed endpoints overlap or not, use the **IntervalArray.overlaps()** method in Pandas.

At first, import the required libraries −

import pandas as pd

Two intervals overlap if they share a common point, including closed endpoints. Create an IntervalArray

intervals = pd.arrays.IntervalArray.from_tuples([(10, 20), (15, 35)])

Display the IntervalArray −

print("IntervalArray...\n",intervals)

Check Intervals that share closed endpoints overlap or not. We have set closed on the left-side with the "left" value of the "closed" parameter −

print("\nDoes interval that share closed endpoints overlap or not...\n",intervals.overlaps(pd.Interval(15,28, closed='left')))

## Example

Following is the code −

import pandas as pd # Two intervals overlap if they share a common point, including closed endpoints # Create an IntervalArray intervals = pd.arrays.IntervalArray.from_tuples([(10, 20), (15, 35)]) # Display the IntervalArray print("IntervalArray...\n",intervals) # Display the interval length print("\nInterval length...\n",intervals.length) # Check Intervals that share closed endpoints overlap or not # We have set closed on the left-side with the "left" value of the "closed" parameter print("\nDoes interval that share closed endpoints overlap or not...\n",intervals.overlaps(pd.Interval(15,28, closed='left')))

## Output

This will produce the following output −

IntervalArray... <IntervalArray> [(10, 20], (15, 35]] Length: 2, dtype: interval[int64, right] Interval length... Int64Index([10, 20], dtype='int64') Does interval that share closed endpoints overlap or not... [ True True]

- Related Articles
- Python Pandas IntervalIndex - Check if Intervals that share closed endpoints overlap
- Python Pandas - Check whether two Interval objects that share closed endpoints overlap
- Python Pandas IntervalArray - Check Intervals that only have an open endpoint in common overlap or not
- Python Pandas IntervalIndex - Check if Intervals that only have an open endpoint in common overlap or not
- Python Pandas - Check whether the intervals in IntervalArray are closed on the left-side, right-side, both or neither
- Python Pandas - Check whether two Interval objects that share an open endpoint overlap
- Python Pandas - Check if the Intervals in the IntervalArray is empty
- 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 - Create a half-closed time interval and check for existence of endpoints
- Python Pandas - Create a closed time interval and check for existence of both the endpoints
- Python Pandas - Check whether the IntervalIndex intervals are closed on the left-side, right-side, both or neither
- Python Pandas - Check whether two Interval objects overlap
- 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
- Check if any two intervals overlap among a given set of intervals in C++

Advertisements