Check if single cell value is NaN in Pandas

前端 未结 4 1184
抹茶落季
抹茶落季 2020-12-08 06:53

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

4条回答
  •  -上瘾入骨i
    2020-12-08 07:16

    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
    

提交回复
热议问题