How to return the midpoint of an IntervalArray object as an index
Overview
The mid attribute of an IntervalArray object returns the midpoints of the object's intervals as an index.
IntervalArrayis an object containing interval data such that they are closed on the same side.
Syntax
The mid attribute has the following syntax:
IntervalArray.mid
The syntax for the mid attribute of an IntervalArray object in pandas
Parameter value
Since mid is an attribute, it takes no parameter value.
Return value
The mid attribute returns the midpoints of each interval in the IntervalArray object as an index.
Example
# A code to illustrate the mid attribute of an IntervalArray object.# importing the pandas libraryimport pandas as pd# creating the IntervalArray objecta = pd.arrays.IntervalArray([pd.Interval(0, 4), pd.Interval(1, 5)])# printing the ItervalArray objectprint(a)# obtaining the midpointsprint("This is the midpoint: ", a.mid)
Explanation
- Line 3: We import the pandas library.
- Line 6: We create an
IntervalArrayobject,a. - Line 9: We print the value of
a. - Line 12: We use the
midattribute to obtain the midpoints of each interval ofa.