
- 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 IntervalIndex - Indicates if an interval is empty (contains no points)
To indicate if an interval is empty (contains no points), use the interval.is_empty property in Pandas. At first, import the required libraries −
import pandas as pd
Create IntervalIndex −
interval = pd.IntervalIndex.from_arrays([0, 0], [0, 0])
Display the interval −
print("IntervalIndex...\n",interval)
Check if the interval is empty −
print("\nIs the interval empty?\n",interval.is_empty)
Example
Following is the code −
import pandas as pd # Create IntervalIndex interval = pd.IntervalIndex.from_arrays([0, 0], [0, 0]) # Display the interval print("IntervalIndex...\n",interval) # Display the interval length print("\nIntervalIndex length...\n",interval.length) # check if the interval is empty print("\nIs the interval empty?\n",interval.is_empty)
Output
This will produce the following output −
IntervalIndex... IntervalIndex([(0, 0], (0, 0]], dtype='interval[int64, right]') IntervalIndex length... Int64Index([0, 0], dtype='int64') Is the interval empty? [ True True]
- Related Articles
- 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 - Check if an interval is empty
- Python Pandas - Check if an interval set as open is empty
- Python Pandas - Check if an interval is empty if closed from the left side
- Python Pandas - Check if an interval is empty if closed from the both sides
- Python Pandas - Create an IntervalIndex
- Python Pandas IntervalIndex - Get the locations of all the relevant interval if a label is in several intervals
- Python Pandas - Check if an element belongs to an Interval
- Python Pandas - Check if the IntervalIndex has overlapping intervals
- Python Pandas - Check if an Interval is closed on the left side
- Python Pandas - Check if an Interval is closed on the right side
- Python Pandas IntervalIndex - Check if Intervals that share closed endpoints overlap
- Python Pandas - Check if the Pandas Index holds Interval objects
- Python - Check if Pandas dataframe contains infinity

Advertisements