Filtering all rows with NaT in a column in Dataframe python

后端 未结 4 1383
有刺的猬
有刺的猬 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:25

    isnull and notnull work with NaT so you can handle them much the same way you handle NaNs:

    >>> df
    
       a          b  c
    0  1        NaT  w
    1  2 2014-02-01  g
    2  3        NaT  x
    
    >>> df.dtypes
    
    a             int64
    b    datetime64[ns]
    c            object
    

    just use isnull to select:

    df[df.b.isnull()]
    
       a   b  c
    0  1 NaT  w
    2  3 NaT  x
    

提交回复
热议问题