I have the following df:
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!
Advertisement
Answer
I think this is what you’re asking:
JavaScript
x
2
1
df[~(df.le(95) & df.columns.str.contains("test"))].dropna()
2
Example (df
):
JavaScript
1
6
1
pump.test Speed feed.test water
2
0 100 1000 70 0.2
3
1 100 2000 100 0.3
4
2 100 3000 100 0.4
5
3 95 4000 100 0.5
6
Output of the operation above:
JavaScript
1
4
1
pump.test Speed feed.test water
2
1 100 2000 100 0.3
3
2 100 3000 100 0.4
4