- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- 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 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]
Advertisements