Py4JError: An error occurred while calling o230.and

Py4JError: An error occurred while calling o230.and

谁能帮忙解决这个错误?我在 Pyspark 中编程,我正在尝试使用以下代码计算某个偏差:

Result =   data.select(count(((coalesce(data["pred"], lit(0)))!=0 & (coalesce(data["val"],lit(0)) !=0
& (abs(coalesce(data["pred"], lit(0)) - coalesce(data["val"],lit(0)))/(coalesce(data["val"],lit(0)))) > 0.1))))

出现以下错误:

"Py4JError: An error occurred while calling o230.and. Trace:
py4j.Py4JException: Method and([class java.lang.Integer]) does not exist 
at py4j.reflection.ReflectionEngine.getMethod(ReflectionEngine.java:318)
    at py4j.reflection.ReflectionEngine.getMethod(ReflectionEngine.java:326)
    at py4j.Gateway.invoke(Gateway.java:274)
    at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
    at py4j.commands.CallCommand.execute(CallCommand.java:79)
    at py4j.GatewayConnection.run(GatewayConnection.java:238)
    at java.lang.Thread.run(Thread.java:748)"

我对使用 pyspark 进行编程非常陌生,根本无法发现我的代码有什么问题;我用非常相似的代码进行了非常相似的计算,但运行正常...有人知道这个问题吗?

PS除其他外,这段代码是一种不同的计算,具有相似的语法:

Abs_avg = data.select(avg(abs(coalesce(data["pred"], lit(0)) - coalesce(data["val"],lit(0)))))

条件需要用括号括起来,否则会解释为0 & something。此外,您不需要将 ... 包装在 (...) != 0.

Result = data.select(
    count(
        (coalesce(data["pred"], lit(0)) != 0) & 
        (coalesce(data["val"], lit(0)) != 0) & 
        (abs(
             coalesce(data["pred"], lit(0)) - 
             coalesce(data["val"], lit(0))
            ) / coalesce(data["val"], lit(0)) > 0.1
        )
    )
)