How to select rows with one or more nulls from a pandas DataFrame without listing columns explicitly?

后端 未结 5 2124
滥情空心
滥情空心 2020-11-28 00:37

I have a dataframe with ~300K rows and ~40 columns. I want to find out if any rows contain null values - and put these \'null\'-rows into a separate dataframe so that I coul

5条回答
  •  庸人自扰
    2020-11-28 01:30

    Four fewer characters, but 2 more ms

    %%timeit
    df.isna().T.any()
    # 52.4 ms ± 352 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
    
    %%timeit
    df.isna().any(axis=1)
    # 50 ms ± 423 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
    

    I'd probably use axis=1

提交回复
热议问题