Python Pandas - Get the left bound for the interval


To get the left bound for the interval, use the interval.left 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 "left". Get the left bound for the interval

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)

Get the left bound

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

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 "left"
# Get the left bound for the interval
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)

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

Output

This will produce the following code

Interval...
[2020-01-01, 2021-01-01)

Interval length...
366 days 00:00:00

The left bound for the Interval...
2020-01-01 00:00:00

Updated on: 20-Oct-2021

238 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements