简体   繁体   中英

PySpark DataFrame unable to drop duplicates

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM