Python Pandas - Get the right bound for the IntervalIndex

To get the right bound for the IntervalIndex, use the interval.right property in Pandas. The right bound represents the upper endpoint of each interval in the IntervalIndex.

Creating IntervalIndex

First, let's create an IntervalIndex using from_arrays() method ?

import pandas as pd

# Create IntervalIndex from left and right arrays
interval = pd.IntervalIndex.from_arrays([5, 10, 15], [15, 20, 25])

# Display the interval
print("IntervalIndex...")
print(interval)
IntervalIndex...
IntervalIndex([(5, 15], (10, 20], (15, 25]], dtype='interval[int64, right]')

Getting the Right Bound

Use the right property to extract the right bounds of all intervals ?

import pandas as pd

# Create IntervalIndex
interval = pd.IntervalIndex.from_arrays([5, 10, 15], [15, 20, 25])

# Get the right bound
print("The right bound for the IntervalIndex...")
print(interval.right)
The right bound for the IntervalIndex...
Index([15, 20, 25], dtype='int64')

Complete Example

Here's a comprehensive example showing IntervalIndex properties including the right bound ?

import pandas as pd

# Create IntervalIndex
interval = pd.IntervalIndex.from_arrays([5, 10, 15], [15, 20, 25])

# Display the interval
print("IntervalIndex...")
print(interval)

# Display the interval length
print("\nIntervalIndex length...")
print(interval.length)

# Check whether the IntervalIndex is closed on the left-side, right-side, both or neither
print("\nChecking for the type of IntervalIndex...")
print(interval.closed)

# Get the right bound
print("\nThe right bound for the IntervalIndex...")
print(interval.right)
IntervalIndex...
IntervalIndex([(5, 15], (10, 20], (15, 25]], dtype='interval[int64, right]')

IntervalIndex length...
Index([10, 10, 10], dtype='int64')

Checking for the type of IntervalIndex...
right

The right bound for the IntervalIndex...
Index([15, 20, 25], dtype='int64')

Key Points

  • The right property returns an Index containing the right endpoints
  • For intervals like (5, 15], the right bound is 15
  • The returned Index has the same dtype as the original interval bounds
  • You can also use left property to get left bounds

Conclusion

Use the right property to extract right bounds from IntervalIndex. This property returns an Index object containing all the upper endpoints of the intervals.

Updated on: 2026-03-26T16:57:52+05:30

184 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements