Python Pandas IntervalIndex - Check if Intervals that only have an open endpoint in common overlap or not

PythonServer Side ProgrammingProgramming

Beyond Basic Programming - Intermediate Python

Most Popular

36 Lectures 3 hours

Practical Machine Learning using Python

Best Seller

91 Lectures 23.5 hours

Practical Data Science using Python

22 Lectures 6 hours

To check if Intervals that only have an open endpoint in common overlap or not, use the IntervalIndex.is_overlapping property.

At first, import the required libraries −

import pandas as pd

Create IntervalIndex. The intervals are closed on the left-side since the "closed" parameter is set "left" −

interval = pd.interval_range(0, 8, closed='left')


Display the interval −

print("IntervalIndex...",interval)

Check if the Intervals that only have an open endpoint in common overlap or not −

print("Does the Intervals that have an open endpoint overlap?",interval.is_overlapping)

Example

Following is the code −

import pandas as pd

# Create IntervalIndex
# The intervals are closed on the left-side since the "closed" parameter is set "left"
interval = pd.interval_range(0, 8, closed='left')

# Display the interval
print("IntervalIndex...",interval)

# Display the interval length
print("IntervalIndex length...",interval.length)

# Check if the Intervals that only have an open endpoint in common overlap or not
print("Does the Intervals that have an open endpoint overlap?",interval.is_overlapping)

Output

This will produce the following output −

IntervalIndex...
IntervalIndex([[0, 1), [1, 2), [2, 3), [3, 4), [4, 5), [5, 6), [6, 7), [7, 8)], dtype='interval[int64, left]')

IntervalIndex length...
Int64Index([1, 1, 1, 1, 1, 1, 1, 1], dtype='int64')

Does the Intervals that have an open endpoint overlap?
False
Updated on 18-Oct-2021 07:55:25

Advertisements