Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

pandas
python

Obtain the length of each interval of an IntervalArray object

Onyejiaku Theophilus Chidalu

Overview

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

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

Syntax

IntervalArray.length
Syntax for the length attribute of an IntervalArray object

Parameters

This attribute takes no parameter value.

Return value

This attribute returns the length of each interval of the IntervalArray object as an index.

Example

# A code to illustrate the length 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)])

# printing the IntervalArray object
print(a)

# obtaining the midpoints
print("This length of each interval is: ", a.length)
Implementing the length attribute of an IntervalArray object

Explanation

  • Line 3: We import the pandas library.
  • Line 6: We create an IntervalArray object, a.
  • Line 9: We print the value of a.
  • Line 12: We use the length attribute to obtain the length of each interval of a.

RELATED TAGS

pandas
python

CONTRIBUTOR

Onyejiaku Theophilus Chidalu
RELATED COURSES

View all Courses

Keep Exploring