
- 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 - Get the length from the IntervalIndex
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')
- Related Articles
- Python Pandas - Get the midpoint from the IntervalIndex
- Python Pandas - Get the left bound for the IntervalIndex
- Python Pandas - Get the right bound for the IntervalIndex
- Python Pandas IntervalIndex - Get integer location for requested label
- Python Pandas - Create an IntervalIndex
- Python Pandas - Get the length of the Interval
- Python Pandas - Check if the IntervalIndex has overlapping intervals
- Python Pandas - Get a tuple with the length of each level from MultiIndex
- Python Pandas IntervalIndex - Get the locations of all the relevant interval if a label is in several intervals
- Python Pandas - Check elementwise if the Intervals in the IntervalIndex contain the value
- Python Pandas - Get the year from the Period object
- Python Pandas - Get the year from the PeriodIndex object
- Check elementwise if the Intervals in the IntervalIndex contain the value in Python Pandas
- Python - Get the weekday from Timestamp object in Pandas
- Python Pandas - Get the number of days from TimeDelta

Advertisements