在数据框python的列中使用NaT过滤所有行 [英] Filtering all rows with NaT in a column in Dataframe python
本文介绍了在数据框python的列中使用NaT过滤所有行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的df:
a b c
1 NaT w
2 2014-02-01 g
3 NaT x
df=df[df.b=='2014-02-01']
会给我
a b c
2 2014-02-01 g
我想要一个在b列中包含NaT的所有行的数据库吗?
I want a database of all rows with NaT in column b?
df=df[df.b==None] #Doesn't work
我想要这个:
a b c
1 NaT w
3 NaT x
推荐答案
isnull
和notnull
与NaT
一起使用,因此您可以像处理NaNs
一样处理它们:
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
只需使用isnull
进行选择:
df[df.b.isnull()]
a b c
0 1 NaT w
2 3 NaT x
这篇关于在数据框python的列中使用NaT过滤所有行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文