

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
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 Questions & Answers
- Python Pandas - Get the midpoint from the IntervalIndex
- Python Pandas - Get the length from the IntervalIndex
- Python Pandas IntervalIndex - Indicates if an interval is empty (contains no points)
- 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 - Create an Index based on an underlying Categorical
- Python Pandas IntervalIndex - Check if Intervals that only have an open endpoint in common overlap or not
- 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