
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
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
Get Length from IntervalIndex in Python Pandas
To get the length from the IntervalIndex, use the interval.length property in Pandas. At first, import the required libraries −
import pandas as pd
Create IntervalIndex −
interval = pd.IntervalIndex.from_arrays([10, 15, 20], [20, 25, 30])
Display the interval −
print("IntervalIndex...\n",interval)
Display the interval length −
print("\nIntervalIndex length...\n",interval.length)
Example
Following is the code −
import pandas as pd # Create IntervalIndex interval = pd.IntervalIndex.from_arrays([10, 15, 20], [20, 25, 30]) # Display the interval print("IntervalIndex...\n",interval) # Display the interval length print("\nIntervalIndex length...\n",interval.length) # return the midpoint of the Interval print("\nThe midpoint for the Interval...\n",interval.mid)
Output
This will produce the following output −
IntervalIndex... IntervalIndex([(10, 20], (15, 25], (20, 30]], dtype='interval[int64, right]') IntervalIndex length... Int64Index([10, 10, 10], dtype='int64') The midpoint for the Interval... Float64Index([15.0, 20.0, 25.0], dtype='float64')
Advertisements