Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if single cell value is NaN in Pandas

Tags:

python

pandas

nan

I just want to check if a single cell in Pandas series is null or not i.e. to check if a value is NaN.

All other answers are for series and arrays, but not for single value.

I have tried pandas.notnull, pandas.isnull, numpy.isnan. Is there a solution for a single value only?

like image 329
vidit Avatar asked Jan 03 '15 12:01

vidit


People also ask

How can I check if a panda cell is NaN?

Check If any Value is NaN in pandas DataFrameUse DataFrame. isnull(). Values. any() method to check if there are any missing data in pandas DataFrame, missing data is represented as NaN or None values in DataFrame.

How do you check if a value is a NaN Python?

The math. isnan() method checks whether a value is NaN (Not a Number), or not. This method returns True if the specified value is a NaN, otherwise it returns False.


1 Answers

Try this:

import pandas as pd import numpy as np from pandas import *  >>> L = [4, nan ,6] >>> df = Series(L)  >>> df 0     4 1   NaN 2     6  >>> if(pd.isnull(df[1])):         print "Found"  Found  >>> if(np.isnan(df[1])):         print "Found"  Found 
like image 194
Shahriar Avatar answered Oct 05 '22 13:10

Shahriar