简体   繁体   中英

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

I have the following 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). 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 ?

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 .

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

    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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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