当特定列在pandas中具有空值时选择数据 [英] Select data when specific columns have null value in pandas
本文介绍了当特定列在pandas中具有空值时选择数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个数据框,其中有两个我要过滤的日期字段,并且当任何一个日期字段为null时,都可以查看行.
I have a dataframe where there are 2 date fields I want to filter and see rows when any one of the date field is null.
ID Date1 Date2
58844880 04/11/16 NaN
59745846 04/12/16 04/14/16
59743311 04/13/16 NaN
59745848 04/14/16 04/11/16
59598413 NaN NaN
59745921 04/14/16 04/14/16
59561199 04/15/16 04/15/16
NaN 04/16/16 04/16/16
59561198 NaN 04/17/16
应如下图所示
ID Date1 Date2
58844880 04/11/16 NaN
59743311 04/13/16 NaN
59598413 NaN NaN
59561198 NaN 04/17/16
尝试过代码
df = (df['Date1'].isnull() | df['Date1'].isnull())
推荐答案
使用 时间:
#[900000 rows x 3 columns]
df = pd.concat([df]*100000).reset_index(drop=True)
In [12]: %timeit (df[df['Date1'].isnull() | df['Date2'].isnull()])
10 loops, best of 3: 89.3 ms per loop
In [13]: %timeit (df[df.filter(like='Date').isnull().any(1)])
10 loops, best of 3: 146 ms per loop
这篇关于当特定列在pandas中具有空值时选择数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文