# Python Pandas - Check if the interval is open on the right side

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 the interval is open on the right side, use the interval.open_right 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(5, 20, closed='neither')

Display the interval

print("Interval...",interval)


Check whether the interval is open on the right side

print("Check if the interval is open on the right side...",interval.open_right)

## 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(5, 20, closed='neither')

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

# the left bound
print("The left bound for the Interval...",interval.left)

# the right bound
print("The right bound for the Interval...",interval.right)

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

# check whether the interval is open on the right side
print("Check if the interval is open on the right side...",interval.open_right)

## Output

This will produce the following code

Interval...
(5, 20)

The left bound for the Interval...
5

The right bound for the Interval...
20

Interval length...
15

Check if the interval is open on the right side...
True
Updated on 21-Oct-2021 06:42:08