pyspark.sql.Window#

class pyspark.sql.Window[source]#

Utility functions for defining window in DataFrames.

New in version 1.4.0.

Changed in version 3.4.0: Supports Spark Connect.

Notes

When ordering is not defined, an unbounded window frame (rowFrame, unboundedPreceding, unboundedFollowing) is used by default. When ordering is defined, a growing window frame (rangeFrame, unboundedPreceding, currentRow) is used by default.

Examples

>>> # ORDER BY date ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
>>> window = Window.orderBy("date").rowsBetween(Window.unboundedPreceding, Window.currentRow)
>>> # PARTITION BY country ORDER BY date RANGE BETWEEN 3 PRECEDING AND 3 FOLLOWING
>>> window = Window.orderBy("date").partitionBy("country").rangeBetween(-3, 3)

Methods

orderBy(*cols)

Creates a WindowSpec with the ordering defined.

partitionBy(*cols)

Creates a WindowSpec with the partitioning defined.

rangeBetween(start, end)

Creates a WindowSpec with the frame boundaries defined, from start (inclusive) to end (inclusive).

rowsBetween(start, end)

Creates a WindowSpec with the frame boundaries defined, from start (inclusive) to end (inclusive).

Attributes

currentRow

unboundedFollowing

unboundedPreceding