简体   繁体   English

如果任何特定列包含特定值,则删除 pandas 数据框中的行

[英]Remove rows in pandas dataframe if any of specific columns contains a specific value

I have the following df:我有以下df:

Data Frame数据框

I have not been able to figure out how to delete a row if any of the columns containing the word "test" is less than 95. For example, I would have to delete the entire index row 1 because the column "heat.test" is 80 (the same for rows 0 and 3).如果包含单词“test”的任何列小于 95,我无法弄清楚如何删除一行。例如,我将不得不删除整个索引第 1 行,因为列“heat.test”为 80(第 0 行和第 3 行相同)。 In other words, if only one column meets this condition, the whole row must be deleted.换句话说,如果只有一列满足该条件,则必须删除整行。

Thank you!谢谢!

Your question was not clear.你的问题不清楚。 Did you mean that a row need to be delete if pump.test < 95 or feed.test < 95 ?您的意思是如果pump.test < 95feed.test < 95需要删除一行?

In that case don't delete or remove just do it the other way around und do a positive selection .在这种情况下,不要删除删除,只是反过来做,然后做一个积极的选择 Select all rows where feed.test and pump.test is equal or greater then 95 .选择feed.testpump.test 等于或大于95的所有行。

df.loc[df['feed.test'].ge(95) & df['pump.test'].ge(95)]

I think this is what you're asking:我想这就是你要问的:

df[~(df.le(95) & df.columns.str.contains("test"))].dropna()

Example ( df ):示例( df ):

    pump.test  Speed  feed.test  water
0   100        1000   70         0.2
1   100        2000   100        0.3
2   100        3000   100        0.4
3   95         4000   100        0.5

Output of the operation above:上述操作的输出:

    pump.test  Speed  feed.test  water
1   100        2000   100        0.3
2   100        3000   100        0.4

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

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