![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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
How to check if any value is NaN in a Pandas DataFrame?
To check if any value is NaN in a Pandas DataFrame, we can use isnull().values.any() method.
Steps
Make a series, s, one-dimensional ndarray with axis labels (including time series).
Print the series, s.
Check whether NaN is present or not.
Create a two-dimensional, size-mutable, potentially heterogeneous tabular data, df.
Print the input DataFrame.
Check whether NaN is present or not.
Example
import pandas as pd import numpy as np s = pd.Series([1, np.nan, 3, np.nan, 3, np.nan, 7, np.nan, 3]) print "Input series is:
", s present = s.isnull().values.any() print "NAN is present in series: ", present df = pd.DataFrame( { "x": [5, np.nan, 1, np.nan], "y": [np.nan, 1, np.nan, 10], "z": [np.nan, 1, np.nan, np.nan] } ) print "
Input DataFrame is:
", df present = df.isnull().values.any() print "
NAN present in DataFrame:", present
Output
Input series is: 0 1.0 1 NaN 2 3.0 3 NaN 4 3.0 5 NaN 6 7.0 7 NaN 8 3.0 dtype: float64 NAN is present in series: True Input DataFrame is: x y z 0 5.0 NaN NaN 1 NaN 1.0 1.0 2 1.0 NaN NaN 3 NaN 10.0 NaN NAN present in DataFrame: True
Advertisements