pyspark.sql.
Window
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)
orderBy
Creates a WindowSpec with the ordering defined.
WindowSpec
partitionBy(*cols)
partitionBy
Creates a WindowSpec with the partitioning defined.
rangeBetween(start, end)
rangeBetween
Creates a WindowSpec with the frame boundaries defined, from start (inclusive) to end (inclusive).
rowsBetween(start, end)
rowsBetween
Attributes
currentRow
unboundedFollowing
unboundedPreceding