Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

pandas

How to return left endpoints of IntervalArray object as an index

Onyejiaku Theophilus Chidalu

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)
Implementing the left attribute of an IntervalArray object

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.

RELATED TAGS

pandas

CONTRIBUTOR

Onyejiaku Theophilus Chidalu
RELATED COURSES

View all Courses

Keep Exploring