Check for None in pandas dataframe

前端 未结 2 872
死守一世寂寞
死守一世寂寞 2021-02-15 21:59

I would like to find where None is found in the dataframe.

pd.DataFrame([None,np.nan]).isnull()
OUT: 
      0
0  True
1  True

isnull() finds bo

2条回答
  •  南笙
    南笙 (楼主)
    2021-02-15 22:46

    You could use applymap with a lambda to check if an element is None as follows, (constructed a different example, as in your original one, None is coerced to np.nan because the data type is float, you will need an object type column to hold None as is, or as commented by @Evert, None and NaN are indistinguishable in numeric type columns):

    df = pd.DataFrame([[None, 3], ["", np.nan]])
    
    df
    #      0      1
    #0  None    3.0
    #1          NaN
    
    df.applymap(lambda x: x is None)
    
    #       0       1
    #0   True   False
    #1  False   False
    

提交回复
热议问题