PySpark DataFrame 无法删除重复项

PySpark DataFrame unable to drop duplicates

您好,我创建了一个 spark 数据框,我正在尝试删除重复项:

df.drop_duplicates(subset='id')

我收到以下错误:

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)

正在使用 osx 10.11.4,火花 1.6.1

我运行一个像这样的jupyter笔记本

PYSPARK_DRIVER_PYTHON=jupyter PYSPARK_DRIVER_PYTHON_OPTS='notebook' pyspark

是否还有其他一些我可能遗漏或错误的配置?

drop_duplicates / dropDuplicates 的参数应该是名称的集合,Java 等同于可以转换为 Scala Seq,而不是单个字符串。您可以使用 list:

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

tuple:

df.drop_duplicates(subset=('id', ))