Azure Databricks:如何过滤数据框中不包含类似运算符的列?

Posted

技术标签:

【中文标题】Azure Databricks:如何过滤数据框中不包含类似运算符的列?【英文标题】:Azure Databricks : How to filter a column with not like operator in data-frame? 【发布时间】:2019-11-24 07:40:07 【问题描述】:

我必须从数据框中排除列 Justification 不包含单词 spare 的行:

"Justification":"WIWYNN | MSASM Spares | 21| MDM: 2520171"

我尝试了以下方法,但没有任何效果。(我正在使用 spark python)

df= df.where(~ df["Justification"].like("%spares%"))
df = df.where(~(col("Justification").like("%spare%")))
df = df.where("Justification not like '%spare%'")

返回结果,其中 justification 列中包含 spare 单词,即使我已经进行了否定。

我想要完全相反的结果

【问题讨论】:

尝试使用较低的函数 df.where(~(lower(col("Justification")).like("%spare%"))) 成功了,谢谢。我什至没有想到要使用lower。我虽然不区分大小写 【参考方案1】:

试试下面的代码。就像是区分大小写的。您需要在比较之前使用 Lower 函数。

df.where(~(lower(col("Justification")).like("%spare%")))

【讨论】:

以上是关于Azure Databricks:如何过滤数据框中不包含类似运算符的列?的主要内容,如果未能解决你的问题,请参考以下文章