python Pandas - Return the left endpoints of each Interval in the IntervalArray as an Index

To return the left endpoints of each Interval in the IntervalArray as an Index, use the array.left property. This property extracts the starting values of each interval and returns them as a pandas Index object.

What is an IntervalArray?

An IntervalArray is a pandas data structure that holds an array of Interval objects. Each interval represents a range between two values with defined boundaries (open or closed).

Creating IntervalArray and Getting Left Endpoints

Let's create an IntervalArray and extract the left endpoints using the left property −

import pandas as pd

# Create two Interval objects
interval1 = pd.Interval(10, 25)
interval2 = pd.Interval(15, 70)

# Display the intervals
print("Interval1...")
print(interval1)
print("Interval2...")
print(interval2)

# Construct a new IntervalArray from Interval objects
array = pd.arrays.IntervalArray([interval1, interval2])

# Display the IntervalArray
print("\nOur IntervalArray...")
print(array)

# Get the left endpoints
print("\nThe left endpoints of each Interval in the IntervalArray as an Index...")
print(array.left)
Interval1...
(10, 25]
Interval2...
(15, 70]

Our IntervalArray...
<IntervalArray>
[(10, 25], (15, 70]]
Length: 2, dtype: interval[int64, right]

The left endpoints of each Interval in the IntervalArray as an Index...
Int64Index([10, 15], dtype='int64')

Understanding the Output

The array.left property returns an Int64Index containing the left endpoints [10, 15]. This means the first interval starts at 10 and the second interval starts at 15.

Working with Different Data Types

IntervalArrays can work with different data types like floats or dates −

import pandas as pd

# Create intervals with float values
float_intervals = pd.arrays.IntervalArray([
    pd.Interval(1.5, 3.2),
    pd.Interval(2.8, 5.1),
    pd.Interval(4.0, 7.5)
])

print("Float IntervalArray...")
print(float_intervals)
print("\nLeft endpoints...")
print(float_intervals.left)
Float IntervalArray...
<IntervalArray>
[(1.5, 3.2], (2.8, 5.1], (4.0, 7.5]]
Length: 3, dtype: interval[float64, right]

Left endpoints...
Float64Index([1.5, 2.8, 4.0], dtype='float64')

Comparison with Right Endpoints

Property Description Returns
array.left Left endpoints (start values) Index of left boundaries
array.right Right endpoints (end values) Index of right boundaries
array.length Length of each interval Index of interval lengths

Conclusion

The left property of IntervalArray provides a convenient way to extract starting points of all intervals as a pandas Index. This is useful for data analysis and filtering operations on interval data.

Updated on: 2026-03-26T15:54:40+05:30

199 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements