# Python Pandas - Check if an interval set as open is empty

PythonServer Side ProgrammingProgramming

#### Beyond Basic Programming - Intermediate Python

Most Popular

36 Lectures 3 hours

#### Practical Machine Learning using Python

Best Seller

91 Lectures 23.5 hours

#### Practical Data Science using Python

22 Lectures 6 hours

To check if an interval set as open is empty, use the interval.is_empty property. At first, import the required libraries −

import pandas as pd

Open interval set using the "closed" parameter with value "neither". An open interval (in mathematics denoted by square brackets) does not contains its endpoints, # i.e. the open interval [0, 5] is characterized by the conditions 0 < x < 5

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


Display the interval

print("Interval...",interval)

Check whether interval is empty when it is open i.e. no endpoints. An Interval that does not contain any points is empty

print("Is Interval empty? ",interval.is_empty)


## Example

Following is the code

import pandas as pd

# Open interval set using the "closed" parameter with value "neither"
# An open interval (in mathematics denoted by square brackets) does not contains its endpoints,
# i.e. the open interval [0, 5] is characterized by the conditions 0 < x < 5.
interval = pd.Interval(0, 0, closed='neither')

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

# display the interval length
print("Interval length...",interval.length)

# check whether interval is empty when it is open i.e. no endpoints
# An Interval that does not contain any points 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
Updated on 20-Oct-2021 08:25:09