pandas check if column is null with query function

前端 未结 1 1572
夕颜
夕颜 2021-02-01 22:02

I have pandas dataframe that I want to execute on it query function with isnull() or not isnull() condition like that:

In [67]: df_data = pd.DataFrame({\'a\':[1,         


        
1条回答
  •  伪装坚强ぢ
    2021-02-01 22:25

    Use .:

    a = df_data.query('a.isnull()')
    print (a)
        a
    2 NaN
    
    b = df_data.query('a.notnull()')
    print (b)
          a
    0   1.0
    1  20.0
    3  40.0
    4  50.0
    

    You can use also logic NaN != NaN:

    a = df_data.query('a != a')
    print (a)
        a
     2 NaN
    
    b = df_data.query('a == a')
    print (b)
          a
    0   1.0
    1  20.0
    3  40.0
    4  50.0
    

    0 讨论(0)
提交回复
热议问题