
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python Pandas - Create an open time interval and check for existence of both the endpoints
To create an open time interval, use the pandas.Interval() and set the closed parameter to neither. To check for existence of both the endpoints, use the in 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(left=0, right=20, closed='neither')
Display the interval
print("Interval...\n",interval)
Check for the existence of an element in an Interval. This shows that closed = neither does not contain 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)
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(left=0, right=20, closed='neither') # display the interval print("Interval...\n",interval) # display the interval length print("\nInterval length...\n",interval.length) # check for the existence of an element in an Interval # This shows that closed = neither does not contain 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)
Output
This will produce the following code
Interval... (0, 20) Interval length... 20
- Related Articles
- Python Pandas - Create a half-open time interval and check for existence of endpoints
- Python Pandas - Create a closed time interval and check for existence of both the endpoints
- Python Pandas - Create a half-closed time interval and check for existence of endpoints
- Python Pandas - Check if an interval set as open is empty
- Python Pandas - Check whether two Interval objects that share closed endpoints overlap
- Python Pandas - Check whether two Interval objects that share an open endpoint overlap
- Python Pandas - Construct an IntervalArray from an array of splits and return the left endpoints of each interval
- Python Pandas - Construct an IntervalArray from an array of splits and return the right endpoints of each interval
- 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 both sides
- python Pandas - Return the left endpoints of each Interval in the IntervalArray as an Index
- Python Pandas - Return the right endpoints of each Interval in the IntervalArray as an Index
- Python Pandas - Construct an IntervalArray from an array-like of tuples and return the right endpoints of each Interval
- Python Pandas - Construct an IntervalArray from an array-like of tuples and return the left endpoints of each Interval

Advertisements