[英]Drop rows with specific values in all columns Pandas
I got a dataframe and I want to drop all the rows that contain a value >= 100 in all the columns (in the whole dataframe), not in just one specific column.我得到一个 dataframe,我想删除所有列(在整个数据框中)中包含值 >= 100 的所有行,而不仅仅是一个特定的列。 I tried: df = df[(df < 100).any()] df.drop(df[(df <= 100)].index, inplace=True)
我试过: df = df[(df < 100).any()] df.drop(df[(df <= 100)].index, inplace=True)
But nothing work... Could you please help?但是没有任何效果......你能帮忙吗?
Once you have the Boolean mask ( df >= 100
or df.ge(100)
) you can select the rows where all values are True
with all(axis=1)
, then reverse the resulting mask with ~
to select the desired rows from the original df.一旦你有了 Boolean 掩码(
df >= 100
或df.ge(100)
)你可以 select 所有值都为True
的行all(axis=1)
,然后用~
反转生成的掩码到 select 所需的行原来的df
df = df[~df.ge(100).all(axis=1)]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.