
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Check Overlapping Intervals in Pandas IntervalArray
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]
Advertisements