pyspark.sql.functions.nth_value

pyspark.sql.functions.nth_value(col, offset, ignoreNulls=False)[source]

Window function: returns the value that is the offsetth row of the window frame (counting from 1), and null if the size of window frame is less than offset rows.

It will return the offsetth non-null value it sees when ignoreNulls is set to true. If all values are null, then null is returned.

This is equivalent to the nth_value function in SQL.

New in version 3.1.0.

Parameters
colColumn or str

name of column or expression

offsetint, optional

number of row to use as the value

ignoreNullsbool, optional

indicates the Nth value should skip null in the determination of which row to use