 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Pandas - Construct an IntervalArray from an array-like of tuples and return the right endpoints of each Interval
To construct an IntervalArray from an array-like of tuples, use the pandas.arrays.IntervalArray.from_tuples() method. To return the right endpoints of each Interval in the IntervalArray, use the array.right property.
At first, import the required libraries −
import pandas as pd
Construct a new IntervalArray from an array-like of tuples −
array = pd.arrays.IntervalArray.from_tuples([(10, 25),(15, 70)])
Display the intervals −
print("Our IntervalArray...\n",array) Get the right endpoints −
print("\nThe right endpoints of each Interval in the IntervalArray as an Index...\n", array.right)  Example
Following is the code −
import pandas as pd # Construct a new IntervalArray from an array-like of tuples array = pd.arrays.IntervalArray.from_tuples([(10, 25),(15, 70)]) # 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 right endpoints print("\nThe right endpoints of each Interval in the IntervalArray as an Index...\n",array.right)  Output
This will produce the following code −
Our IntervalArray... <IntervalArray> [(10, 25], (15, 70]] Length: 2, dtype: interval[int64, right] Our IntervalArray length... Int64Index([15, 55], dtype='int64') The midpoint of each interval in the IntervalArray... Float64Index([17.5, 42.5], dtype='float64') The right endpoints of each Interval in the IntervalArray as an Index... Int64Index([25, 70], dtype='int64')
Advertisements
 