
- 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 - Create an IntervalIndex
To create an IntervalIndex in Pandas, use the pandas.IntervalIndex.from_arrays() method. At first, import the required libraries −
import pandas as pd
Create IntervalIndex −
interval = pd.IntervalIndex.from_arrays([5, 10, 15], [10, 15, 20])
Display the interval −
print("IntervalIndex...\n",interval)
Example
Following is the code −
import pandas as pd # Create IntervalIndex interval = pd.IntervalIndex.from_arrays([5, 10, 15], [10, 15, 20]) # display the interval print("IntervalIndex...\n",interval) # display the interval length print("\nIntervalIndex length...\n",interval.length)
Output
This will produce the following output −
IntervalIndex... IntervalIndex([(5, 10], (10, 15], (15, 20]], dtype='interval[int64, right]') IntervalIndex length... Int64Index([5, 5, 5], dtype='int64')
- Related Articles
- Python Pandas IntervalIndex - Indicates if an interval is empty (contains no points)
- Python Pandas - Get the midpoint from the IntervalIndex
- Python Pandas - Get the length from the IntervalIndex
- Python Pandas IntervalIndex - Return an ndarray of tuples of the form (left, right)
- Python Pandas - Get the left bound for the IntervalIndex
- Python Pandas - Get the right bound for the IntervalIndex
- Python Pandas - Check if the IntervalIndex has overlapping intervals
- Python Pandas IntervalIndex - Get integer location for requested label
- Python Pandas IntervalIndex - Check if an interval that contains points is empty or not
- Python Pandas IntervalIndex - Check if an interval with missing values is empty or not
- Python Pandas IntervalIndex - Check if Intervals that share closed endpoints overlap
- Python Pandas IntervalIndex - Check if Intervals that only have an open endpoint in common overlap or not
- Python Pandas - Create an Index based on an underlying Categorical
- Python Pandas - Check elementwise if the Intervals in the IntervalIndex contain the value
- Check elementwise if the Intervals in the IntervalIndex contain the value in Python Pandas

Advertisements