Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
Python Pandas IntervalIndex - Check if an interval that contains points is empty or not
To check if an interval that contains points is empty or not, use the IntervalIndex.is_empty property in Pandas.
At first, import the required libraries −
import pandas as pd
Create IntervalIndex −
interval = pd.IntervalIndex.from_arrays([0, 1], [1, 2], closed='right')
Display the interval −
print("IntervalIndex...\n",interval)
Check if the interval that contains points is empty or not −
print("\nIs the interval empty?\n",interval.is_empty)
Example
Following is the code −
import pandas as pd
# Create IntervalIndex
interval = pd.IntervalIndex.from_arrays([0, 1], [1, 2], closed='right')
# Display the interval
print("IntervalIndex...\n",interval)
# Display the interval length
print("\nIntervalIndex length...\n",interval.length)
# check if the interval that contains points is empty or not
print("\nIs the interval empty?\n",interval.is_empty)
Output
This will produce the following output −
IntervalIndex... IntervalIndex([(0, 1], (1, 2]], dtype='interval[int64, right]') IntervalIndex length... Int64Index([1, 1], dtype='int64') Is the interval empty? [False False]
Advertisements
