
- 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 - Check if the Pandas Index holds Interval objects
To check if the Pandas Index holds Interval objects, use the index.is_interval() method in Pandas.
At first, import the required libraries -
import pandas as pd
Create Interval objects −
interval1 = pd.Interval(10, 30) interval2 = pd.Interval(30, 50)
Display the intervals −
print("Interval1...\n",interval1) print("Interval2...\n",interval2)
Creating Pandas index with Interval object1 and 2 −
index = pd.Index([interval1,interval2])
Check whether index values has only interval objects −
print("\nDoes Index consists of Interval objects?\n", index.is_interval())
Example
Following is the code −
import pandas as pd # create Interval objects interval1 = pd.Interval(10, 30) interval2 = pd.Interval(30, 50) # display the intervals print("Interval1...\n",interval1) print("Interval2...\n",interval2) # Creating Pandas index with Interval object1 and 2 index = pd.Index([interval1,interval2]) # Display the Pandas index print("\nPandas Index...\n",index) # Return the dtype of the data print("\nThe dtype object...\n",index.dtype) # check whether index values has only ints print("\nDoes Index consists of Interval objects?\n", index.is_interval())
Output
This will produce the following output −
Interval1... (10, 30] Interval2... (30, 50] Pandas Index... IntervalIndex([(10, 30], (30, 50]], dtype='interval[int64, right]') The dtype object... interval[int64, right] Does Index consists of Interval objects? True
- Related Articles
- Python - Check if the Pandas Index holds categorical data
- Python Pandas - Check whether two Interval objects overlap
- Python Pandas - Check if an interval is empty
- Python Pandas - Check if the index has NaNs
- Python Pandas - Determine if two Index objects are equal
- Python Pandas - Check if the index has unique values
- Python Pandas - Check if the index has duplicate values
- Python Pandas - Check whether two Interval objects that share closed endpoints overlap
- Python Pandas - Check if an element belongs to an Interval
- Python - Check if the Pandas Index only consists of booleans
- Python - Check if the Pandas Index is a floating type
- Python - Check if the Pandas Index only consists of integers
- Python Pandas - Check if the interval is open on the left side
- Python Pandas - Check if the interval is open on the right side
- Python Pandas - Check whether two Interval objects that share an open endpoint overlap

Advertisements