
- 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 - Check if an interval with missing values is empty or not
To check if an interval with missing values is empty or not, use the IntervalIndex.is_empty property. At first, import the required libraries −
import pandas as pd import numpy as np
Create IntervalIndex with NaN values −
interval = pd.IntervalIndex.from_arrays([np.nan, np.nan], [np.nan, np.nan])
Display the interval −
print("IntervalIndex...\n",interval)
Check if the interval that contains missing values is empty or not −
print("\nIs the interval empty?\n",interval.is_empty)
Example
Following is the code −
import pandas as pd import numpy as np # Create IntervalIndex with NaN values interval = pd.IntervalIndex.from_arrays([np.nan, np.nan], [np.nan, np.nan]) # Display the interval print("IntervalIndex...\n",interval) # Display the interval length print("\nIntervalIndex length...\n",interval.length) # check if the interval that contains missing values is empty or not print("\nIs the interval empty?\n",interval.is_empty)
Output
This will produce the following output −
IntervalIndex... IntervalIndex([nan, nan], dtype='interval[float64, right]') IntervalIndex length... Float64Index([nan, nan], dtype='float64') Is the interval empty? [False False]
- Related Articles
- Python Pandas IntervalIndex - Check if an interval that contains points is empty or not
- Python Pandas IntervalIndex - Indicates if an interval is empty (contains no points)
- 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 IntervalIndex - Check if Intervals that only have an open endpoint in common overlap or not
- Python Pandas - Check if an element belongs to an Interval
- Check elementwise if an Interval overlaps the values in the IntervalArray in Python Pandas
- Python Pandas - Check if the IntervalIndex has overlapping intervals
- Python program to check if the string is empty or not
- Python Pandas - Check if the index is empty with 0 elements
- Python Pandas - Check if an Interval is closed on the left side
- Python Pandas - Check if an Interval is closed on the right side
- How to Check if an Array is Empty or Not in Java

Advertisements