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

穿精又带淫゛_ 提交于 2019-11-27 10:43:06

问题


While working in Pandas in Python...

I'm working with a dataset that contains some missing values, and I'd like to return a dataframe which contains only those rows which have missing data. Is there a nice way to do this?

(My current method to do this is an inefficient "look to see what index isn't in the dataframe without the missing values, then make a df out of those indices.")


回答1:


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)]


来源:https://stackoverflow.com/questions/30447083/python-pandas-return-only-those-rows-which-have-missing-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!