Python, Pandas : Return only those rows which have missing values

ぐ巨炮叔叔 提交于 2019-11-28 18:13:49
metersk

You can use any axis=1 to check for least one True per row, then filter with boolean indexing:

null_data = df[df.isnull().any(axis=1)]

Similar to metersk's answer,

null_data = df[np.logical_or.reduce(df.isnull().values, axis=1)]

Test

n = 2
df = pd.DataFrame({'a':np.tile([0,1,2,3,4,np.nan],n),
                   'b':np.tile([0,1,2,3,np.nan,5],n)})

x = df[np.logical_or.reduce(df.isnull().values,axis=1)]
y = df[df.isnull().any(axis=1)]
x.equals(y)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!