Spark __getnewargs__ error … Method or([class java.lang.String]) does not exist

混江龙づ霸主 提交于 2021-02-16 20:01:20

问题


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)

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


回答1:


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'))


来源:https://stackoverflow.com/questions/49191500/spark-getnewargs-error-method-orclass-java-lang-string-does-not-exis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!