14

Hello I have created a spark dataframe, and I am trying to remove duplicates:

df.drop_duplicates(subset='id')

I get the following error:

Py4JError: An error occurred while calling z:org.apache.spark.api.python.PythonUtils.toSeq. Trace:
py4j.Py4JException: Method toSeq([class java.lang.String]) does not exist
    at py4j.reflection.ReflectionEngine.getMethod(ReflectionEngine.java:335)
    at py4j.reflection.ReflectionEngine.getMethod(ReflectionEngine.java:360)
    at py4j.Gateway.invoke(Gateway.java:254)
    at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:133)
    at py4j.commands.CallCommand.execute(CallCommand.java:79)
    at py4j.GatewayConnection.run(GatewayConnection.java:209)
    at java.lang.Thread.run(Thread.java:745)

Am using osx 10.11.4, spark 1.6.1

I ran a jupyter notebook like this

PYSPARK_DRIVER_PYTHON=jupyter PYSPARK_DRIVER_PYTHON_OPTS='notebook' pyspark

Is there some other configurations that I might have missed out or got wrong?

1 Answer 1

22

Argument for drop_duplicates / dropDuplicates should be a collection of names, which Java equivalent can be converted to Scala Seq, not a single string. You can use either a list:

df.drop_duplicates(subset=['id'])

or a tuple:

df.drop_duplicates(subset=('id', ))
Sign up to request clarification or add additional context in comments.

1 Comment

Damn, thanks. I didn't see that properly. Thought it worked similar to pandas dfs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.