Python Pandas IntervalIndex - Indicates if an interval is empty (contains no points)


To indicate if an interval is empty (contains no points), use the interval.is_empty property in Pandas. At first, import the required libraries −

import pandas as pd

Create IntervalIndex −

interval = pd.IntervalIndex.from_arrays([0, 0], [0, 0])

Display the interval −

print("IntervalIndex...\n",interval)

Check if the interval is empty −

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, 0], [0, 0])

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

# Display the interval length
print("\nIntervalIndex length...\n",interval.length)

# check if the interval is empty
print("\nIs the interval empty?\n",interval.is_empty)

Output

This will produce the following output −

IntervalIndex...
IntervalIndex([(0, 0], (0, 0]], dtype='interval[int64, right]')

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

Is the interval empty?
[ True True]

Updated on: 18-Oct-2021

81 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements