Pandas dropna - store dropped rows

后端 未结 2 2070
旧时难觅i
旧时难觅i 2021-02-18 21:14

I am using the pandas.DataFrame.dropna method to drop rows that contain NaN. This function returns a dataframe that excludes the dropped rows, as shown in the documentation.

2条回答
  •  感情败类
    2021-02-18 22:06

    You can do this by indexing the original DataFrame by using the unary ~ (invert) operator to give the inverse of the NA free DataFrame.

    na_free = df.dropna()
    only_na = df[~df.index.isin(na_free.index)]
    

    Another option would be to use the ufunc implementation of ~.

    only_na = df[np.invert(df.index.isin(na_free.index))]
    

提交回复
热议问题