Check for None in pandas dataframe

前端 未结 2 1446
我在风中等你
我在风中等你 2021-02-15 21:57

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:29

    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
    

提交回复
热议问题