 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP 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 IntervalArray - Check Intervals that only have an open endpoint in common overlap or not
To check Intervals that only have an open endpoint in common overlap or not, 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. Create an IntervalArray −
intervals = pd.arrays.IntervalArray.from_tuples([(10, 20), (20, 35)])
Display the IntervalArray −
print("IntervalArray...\n",intervals) Check Intervals that only have an open endpoint in common overlap or not. We have set closed on the right-side with the "right" value of the "closed" parameter −
print("\nDoes interval that that only have an open endpoint overlap or not...\n",intervals.overlaps(pd.Interval(20,25, closed='right'))) 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), (20, 35)]) # Display the IntervalArray print("IntervalArray...\n",intervals) # Display the interval length print("\nInterval length...\n",intervals.length) # Check Intervals that only have an open endpoint in common overlap or not # We have set closed on the right-side with the "right" value of the "closed" parameter print("\nDoes interval that that only have an open endpoint overlap or not...\n",intervals.overlaps(pd.Interval(20,25, closed='right')))  Output
This will produce the following output −
IntervalArray... <IntervalArray> [(10, 20], (20, 35]] Length: 2, dtype: interval[int64, right] Interval length... Int64Index([10, 15], dtype='int64') Does interval that that only have an open endpoint overlap or not... [False True]
Advertisements
 