Jase Villam Jase Villam - 1 year ago 92
Python Question

Filtering all rows with NaT in a column in Dataframe python

I have a df like this:

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


will give me

a b c
2 2014-02-01 g

I want a database of all rows with NaT in column b?

df=df[df.b==None] #Doesn't work

I want this:

a b c
1 NaT w
3 NaT x

Answer Source

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:


   a   b  c
0  1 NaT  w
2  3 NaT  x
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download