Python Pandas - Check if an interval is empty if closed from the left side

PythonServer Side ProgrammingProgramming

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...
",interval)

Check whether interval is empty

print("
Is Interval empty?
",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...
",interval) # display the interval length print("
Interval length...
",interval.length) # check whether interval is empty print("
Is Interval empty?
",interval.is_empty)

Output

This will produce the following code

Interval...
[0, 0)
Interval length...
0
Is Interval empty?
True
raja
Updated on 20-Oct-2021 08:22:54

Advertisements