Pyspark .startswith 反向不起作用

Pyspark .startswith reverse does not work

我有一个包含多个 mac 地址的数据框。我需要过滤掉 mac 以 'ZBB' 开头的地址。我正在使用对我有意义的解决方案:

import pyspark.sql.functions as f
dffinal = df.filter(f.col("mac_address").startswith("ZBB") === false)

不幸的是,此解决方案不起作用,因为它无法识别 ===,当我输入 == 时,'false' 未定义。不幸的是,我正在尝试 https://sparkbyexamples.com/spark/spark-filter-startswith-endswith-examples/ 的解决方案。谁能指出我的工作解决方案?

python 中的布尔值是大写的,因此 True & False。 Python 不知道三等号 ===.

对于你的问题,你可以按照现在的方式解决。

df.filter(f.col('mac_address').startswith('ZBB') == False)

或者使用波浪号 ~,它执行按位非运算,但在我看来可读性较差。

df.filter(~f.col('mac_address').startswith('ZBB'))