
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python Pandas - Construct an IntervalArray from an array of splits and return the left endpoints of each interval
To construct an IntervalArray from an array of splits, use the pandas.arrays.IntervalArray.from_breaks(). To return the left endpoints of each interval, use the array.left property
At first, import the required libraries −
import pandas as pd
Construct a new IntervalArray from an array-like of splits −
array = pd.arrays.IntervalArray.from_breaks([0, 1, 2, 3, 4, 5])
Display the intervals −
print("Our IntervalArray...\n",array)
Get the left endpoints −
print("\nThe left endpoints of each Interval in the IntervalArray as an Index...\n",array.left)
Example
Following is the code −
import pandas as pd # Construct a new IntervalArray from an array-like of splits array = pd.arrays.IntervalArray.from_breaks([0, 1, 2, 3, 4, 5]) # Display the IntervalArray print("Our IntervalArray...\n",array) # Getting the length of IntervalArray # Returns an Index with entries denoting the length of each Interval in the IntervalArray print("\nOur IntervalArray length...\n",array.length) # midpoint of each Interval in the IntervalArray as an Index print("\nThe midpoint of each interval in the IntervalArray...\n",array.mid) # get the left endpoints print("\nThe left endpoints of each Interval in the IntervalArray as an Index...\n",array.left)
Output
This will produce the following code −
Our IntervalArray... <IntervalArray> [(0, 1], (1, 2], (2, 3], (3, 4], (4, 5]] Length: 5, dtype: interval[int64, right] Our IntervalArray length... Int64Index([1, 1, 1, 1, 1], dtype='int64') The midpoint of each interval in the IntervalArray... Float64Index([0.5, 1.5, 2.5, 3.5, 4.5], dtype='float64') The left endpoints of each Interval in the IntervalArray as an Index... Int64Index([0, 1, 2, 3, 4], dtype='int64')
- Related Articles
- Python Pandas - Construct an IntervalArray from an array of splits and return the right endpoints of each interval
- Python Pandas - Construct an IntervalArray from an array-like of tuples and return the left endpoints of each Interval
- Python Pandas - Construct an IntervalArray from an array-like of tuples and return the right endpoints of each Interval
- Python Pandas - Construct an IntervalArray from an array of splits
- python Pandas - Return the left endpoints of each Interval in the IntervalArray as an Index
- Python Pandas - Return the right endpoints of each Interval in the IntervalArray as an Index
- Python Pandas - Check elementwise if an Interval overlaps the values in the IntervalArray created from an array of splits
- Python Pandas - Construct an IntervalArray from an array-like of tuples
- Python Pandas - Return the midpoint of each Interval in the IntervalArray as an Index
- Python Pandas - Return an Index with entries denoting the length of each Interval in the IntervalArray
- Python Pandas - Create an IntervalArray from an array of splits and check the intervals are closed on the left or right-side, both or neither
- Python Pandas - Create an open time interval and check for existence of both the endpoints
- Python Pandas - Return an IntervalArray identical to the current one but closed on the left side
- Check elementwise if an Interval overlaps the values in the IntervalArray in Python Pandas
- Python Pandas - Check if an interval is empty if closed from the left side

Advertisements