Check if single cell value is NaN in Pandas

vidit picture vidit · Jan 3, 2015 · Viewed 56.6k times · Source

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?

Answer

Shahriar picture Shahriar · Jan 3, 2015

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