[英].query() for negated str.contains()?
I want to filter out every row where a column has a specific string.我想过滤掉列具有特定字符串的每一行。
If I want to filter every row that contains that string:如果我想过滤包含该字符串的每一行:
df.query("column_name.str.contains('stringtosearch')")
But if I want to use .query()
to filter out every row containing that string I need to negate that str.contains()
.但是,如果我想使用
.query()
过滤掉包含该字符串的每一行,我需要否定该str.contains()
。
I do not want to use df[~d["column_name"].str.contains("stringtosearch")]
because I want a unified syntax and I use .query()
everywhere else in my code.我不想使用
df[~d["column_name"].str.contains("stringtosearch")]
因为我想要一个统一的语法,并且我在代码中的其他任何地方都使用.query()
。
How can I do this with .query()
?如何使用
.query()
做到这一点?
Simply with the ~
operator (or not
), as demonstrated in the query docs in indexing .只需使用
~
运算符(或not
),如indexing 中的查询文档所示。
df.query("~column_name.str.contains('stringtosearch')")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.