Python,Pandas:仅返回缺少值的行 [英] Python, Pandas : Return only those rows which have missing values
本文介绍了Python,Pandas:仅返回缺少值的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用Python在Pandas中工作时...
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?
(我目前执行此操作的方法效率很低:看看没有丢失值的数据框中没有什么索引,然后在这些索引中做一个df.")
(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.")
推荐答案
您可以使用布尔索引:
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)]
这篇关于Python,Pandas:仅返回缺少值的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文