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.
Creates a WindowSpec with the partitioning defined.
Syntax
Window.partitionBy(*cols)
Parameters
| Parameter | Type | Description |
|---|---|---|
cols |
str, Column, or list | Names of columns or expressions. |
Returns
WindowSpec
Examples
from pyspark.sql import Window, functions as sf
df = spark.createDataFrame(
[(1, "a"), (1, "a"), (2, "a"), (1, "b"), (2, "b"), (3, "b")], ["id", "category"])
# Show row number ordered by id in each category partition.
window = Window.partitionBy("category").orderBy("id")
df.withColumn("row_number", sf.row_number().over(window)).show()
# +---+--------+----------+
# | id|category|row_number|
# +---+--------+----------+
# | 1| a| 1|
# | 1| a| 2|
# | 2| a| 3|
# | 1| b| 1|
# | 2| b| 2|
# | 3| b| 3|
# +---+--------+----------+