Lưu ý
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử đăng nhập hoặc thay đổi thư mục.
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử thay đổi thư mục.
Window function: returns a sequential number starting at 1 within a window partition.
Syntax
from pyspark.sql import functions as sf
sf.row_number()
Parameters
This function does not take any parameters.
Returns
pyspark.sql.Column: the column for calculating row numbers.
Examples
from pyspark.sql import functions as sf
from pyspark.sql import Window
df = spark.range(3)
w = Window.orderBy(df.id.desc())
df.withColumn("desc_order", sf.row_number().over(w)).show()
+---+----------+
| id|desc_order|
+---+----------+
| 2| 1|
| 1| 2|
| 0| 3|
+---+----------+