如何在Python中使用Pyspark等效的reset_index()

pru*_*raj 7 python python-3.x apache-spark apache-spark-sql pyspark

我想知道 PySpark 中与reset_index()pandas 中使用的命令的等效性。当使用默认命令(reset_index)时,如下:

data.reset_index()
Run Code Online (Sandbox Code Playgroud)

我收到错误:

“DataFrame”对象没有属性“reset_index”错误”

Ben*_*aan 1

就像提到的其他评论一样,如果您确实需要向 DF 添加索引,您可以使用:

from pyspark.sql.functions import monotonically_increasing_id

df = df.withColumn("index_column",monotonically_increasing_id())
Run Code Online (Sandbox Code Playgroud)