How to return left endpoints of IntervalArray object as an index

Overview

The left attribute of an IntervalArray object is used to return the left endpoints intervals of the object as an index.

Note: IntervalArray is an object containing interval data such that the data is closed on the same side.

The left endpoint of an IntervalArray represents the start of the intervals of the object. For example, the intervals, (0, 2) and (3, 4), have their intervals starting from 0 and 3 respectively. Hence, they both represent the left endpoints of the intervals.

Syntax

IntervalArray.left
Syntax for the left attribute

Parameters

The left attribute doesn't take any parameters.

Return value

It returns the left endpoints of the IntervalArray object as an index.

Example

# A code to illustrate the left attribute of an IntervalArray object.
# importing the pandas library
import pandas as pd
# creating the IntervalArray object
a = pd.arrays.IntervalArray([pd.Interval(0, 4), pd.Interval(1, 5)])
# obtaining the left endpoints
print(a.left)

Explanation

  • Line 3: We import the pandas library.
  • Line 6: We create an IntervalArray object, a using the pd.arrays.IntervalArray() function.
  • Line 9: We use the left attribute to obtain the left endpoints of a.

New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources