Filtering all rows with NaT in a column in Dataframe python

后端 未结 4 1396
有刺的猬
有刺的猬 2020-12-28 13:01

I have a df like this:

    a b           c
    1 NaT         w
    2 2014-02-01  g
    3 NaT         x   

    df=df[df.b==\'2014-02-01\']

4条回答
  •  天涯浪人
    2020-12-28 13:26

    I feel that the comment by @DSM is worth a answer on its own, because this answers the fundamental question.

    The misunderstanding comes from the assumption that pd.NaT acts like None. However, while None == None returns True, pd.NaT == pd.NaT returns False. Pandas NaT behaves like a floating-point NaN, which is not equal to itself.

    As the previous answer explain, you should use

    df[df.b.isnull()] # or notnull(), respectively
    

提交回复
热议问题