TDS Archive

An archive of data science, data analytics, data engineering, machine learning, and artificial…

Follow publication

Member-only story

5 Methods to Check for NaN values in in Python

Abhijith Chandradas
TDS Archive
Published in
3 min readFeb 23, 2021

NaN stands for Not A Number and is one of the common ways to represent the missing value in the data. It is a special floating-point value and cannot be converted to any other type than float.

NaN value is one of the major problems in Data Analysis. It is very essential to deal with NaN in order to get the desired results.

Finding and dealing with NaN within an array, series or dataframe is easy. However, identifying a stand alone NaN value is tricky. In this article I explain five methods to deal with NaN in python. The first three methods involves in-built functions from libraries. The last two relies on properties of NaN for finding NaN values.

Method 1: Using Pandas Library

isna() in pandas library can be used to check if the value is null/NaN. It will return True if the value is NaN/null.

import pandas as pd
x = float("nan")
print(f"It's pd.isna : {pd.isna(x)}")
OutputIt's pd.isna : True

Method 2: Using Numpy Library

isnan() in numpy library can be used to check if the value is null/NaN. It is similar to isna() in pandas.

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

TDS Archive
TDS Archive

Published in TDS Archive

An archive of data science, data analytics, data engineering, machine learning, and artificial intelligence writing from the former Towards Data Science Medium publication.

Abhijith Chandradas
Abhijith Chandradas

Written by Abhijith Chandradas

Data Analyst | Hacker | Financial Analyst | Freelancer | IIM MBA | Opensource | Democratize Knowledge | https://www.youtube.com/channel/UCLpBd4gzfIBXm2BPpdHOWdQ

Responses (2)

Write a response