Spark __getnewargs__错误...方法or([[class java.lang.String])不存在 [英] Spark __getnewargs__ error ... Method or([class java.lang.String]) does not exist

查看:119
本文介绍了Spark __getnewargs__错误...方法or([[class java.lang.String])不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据是否在另一列中的列值将列添加到DataFrame中,如下所示:

I am trying to add a column to DataFrame depending on whether column value is in another column as follow:

df = df.withColumn('new_column', when(df['color']=='blue' | df['color']=='green', 'A').otherwise('WD'))

运行代码后,我得到以下错误:

after running the code I obtain the following error:

Py4JError: An error occurred while calling o59.or. Trace:
py4j.Py4JException: Method or([class java.lang.String]) 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:214)
    at java.lang.Thread.run(Thread.java:748)

我该怎么做才能克服这个问题?我正在使用PySpark 2.3.0

what shall I do to overcome this issue? I am using PySpark 2.3.0

推荐答案

在使用多个条件时,由于运算符的优先级,每个条件都需要分开.

While using multiple conditions, each condition needs to be separated because of operator precedence.

df=df.withColumn('new_column',when((df['color']=='blue')|(df['color']=='green'),'A').otherwise('WD'))

这篇关于Spark __getnewargs__错误...方法or([[class java.lang.String])不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆