Check if single cell value is NaN in Pandas

前端 未结 4 1194
抹茶落季
抹茶落季 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条回答
  •  情书的邮戳
    2020-12-08 07:29

    You can use "isnull" with "at" to check a specific value in a dataframe.

    For example:

    import pandas as pd
    import numpy as np
    
    df = pd.DataFrame([[np.nan, 2], [1, 3], [4, 6]], columns=['A', 'B'])
    

    Yeilds:

        A   B
    0   NaN 2
    1   1.0 3
    2   4.0 6
    

    To check the values:

    pd.isnull(df.at[0,'A'])
    

    -> True

    pd.isnull(df.at[0,'B'])
    

    -> False

提交回复
热议问题