Check If an Interval is Empty and Closed from the Left Side in Python Pandas



To check if an interval is empty if closed from the left side, use the interval.is_empty property. At first, import the required libraries −

import pandas as pd

Interval closed from the left. Interval set using the "closed" parameter with value "left"

interval = pd.Interval(0, 0, closed='left')

Display the interval

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

Check whether interval is empty

print("\nIs Interval empty? \n",interval.is_empty)

Example

Following is the code

import pandas as pd

# interval closed from the left
# Interval set using the "closed" parameter with value "left"
interval = pd.Interval(0, 0, closed='left')

# display the interval
print("Interval...\n",interval)

# display the interval length
print("\nInterval length...\n",interval.length)

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

Output

This will produce the following code

Interval...
[0, 0)
Interval length...
0
Is Interval empty?
True
Updated on: 2021-10-20T08:22:54+05:30

78 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements