简体   繁体   English

根据值从 dataframe 中删除所有行

[英]Drop all rows from a dataframe based on value

I have been looking this site and google for an answer to my question, but they all apply to columns.我一直在寻找这个网站和谷歌来寻找我的问题的答案,但它们都适用于列。

In my data set there are a couple of cells which only contain a space, instead of NaN.在我的数据集中,有几个单元格只包含一个空格,而不是 NaN。 So I would like to drop all the rows there this is the case.所以我想删除所有的行,就是这种情况。 I know I can use the code below to do so per column.我知道我可以使用下面的代码按列执行此操作。 But how do I apply this to the entire dataframe?但是如何将其应用于整个 dataframe?

df= df[df.column != ' ']

If need remove all rows with space at least in one column add DataFrame.all for test if all values per rows are True s:如果需要删除至少在一列中有空格的所有行,请添加DataFrame.all以测试每行的所有值是否为True s:

df= df[(df != ' ').all(axis=1)]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM