- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

To check whether the interval is closed on the left-side, right-side, both or neither, use the interval.closed property.

At first, import the required libraries −

import pandas as pd

Closed interval set using the "closed" parameter with value "both". A closed interval (in mathematics denoted by square brackets) contains its endpoints, # i.e. the closed interval [0, 5] is characterized by the conditions 0 <= x <= 5

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

Display the interval

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

Check whether the interval is closed on the left-side, right-side, both or neither

print("\nChecking for the type of Interval...\n",interval.closed)

Following is the code

import pandas as pd # Closed interval set using the "closed" parameter with value "both" # A closed interval (in mathematics denoted by square brackets) contains its endpoints, # i.e. the closed interval [0, 5] is characterized by the conditions 0 <= x <= 5. interval = pd.Interval(left=0, right=20, closed='both') # display the interval print("Interval...\n",interval) # check whether the interval is closed on the left-side, right-side, both or neither print("\nChecking for the type of Interval...\n",interval.closed) # check for the existence of an element in an Interval # This shows that closed = both contains its endpoints print("\nThe left-most element exists in the Interval? = \n",0 in interval) print("\nThe right-most element exists in the Interval? = \n",20 in interval)

This will produce the following code

Interval... [0, 20] Checking for the type of Interval... both

- Related Questions & Answers
- Python Pandas - Check whether the IntervalIndex intervals are closed on the left-side, right-side, both or neither
- Python Pandas - Check whether the intervals in IntervalArray are closed on the left-side, right-side, both or neither
- Python Pandas - Check if an Interval is closed on the left side
- Python Pandas - Check if an Interval is closed on the right side
- Python Pandas - Create an IntervalArray from an array of splits and check the intervals are closed on the left or right-side, both or neither
- Python Pandas - Check if the interval is open on the left side
- Python Pandas - Check if the interval is open on the right side
- Python Pandas - Check if an interval is empty if closed from the left side
- Python Pandas - Return an IntervalArray identical to the current one but closed on the left side
- Why Indian Vehicles steering is on Left Side while few Foreign countries in right side?
- Python Pandas - Check if an interval is empty if closed from the both sides
- Python Pandas - Return an IntervalArray identical to the current one but closed on the specified side
- Python Pandas - Create a closed time interval and check for existence of both the endpoints
- How to move the Y-axis ticks from the left side of the plot to the right side in matplotlib?
- Python Pandas - Check whether two Interval objects that share closed endpoints overlap

Advertisements