Python Pandas - Get the right bound for the interval


To get the right bound for the interval, use the interval.right property. At first, import the required libraries −

import pandas as pd

Use Timestamps as the bounds to create a time interval. Closed interval set using the "closed" parameter with value "right" −

interval = pd.Interval(pd.Timestamp('2020-01-01 00:00:00'),
   pd.Timestamp('2021-01-01 00:00:00'), closed='left')

Get the right bound −

print("\nThe right bound for the Interval...\n",interval.right)

Example

Following is the code −

import pandas as pd

# Use Timestamps as the bounds to create a time interval
# Closed interval set using the "closed" parameter with value "right"
interval = pd.Interval(pd.Timestamp('2020-01-01 00:00:00'),
   pd.Timestamp('2021-01-01 00:00:00'), closed='left')

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

# display the interval length
print("\nInterval length...\n",interval.length)

# get the right bound
print("\nThe right bound for the Interval...\n",interval.right)

Output

This will produce the following code −

Interval...
[2020-01-01, 2021-01-01)
Interval length...
366 days 00:00:00
The right bound for the Interval...
2021-01-01 00:00:00

Updated on: 12-Oct-2021

709 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements