pyspark.sql.functions.desc_nulls_last

pyspark.sql.functions.desc_nulls_last(col: ColumnOrName) → pyspark.sql.column.Column[source]

Returns a sort expression based on the descending order of the given column name, and null values appear after non-null values.

New in version 2.4.0.

Changed in version 3.4.0: Supports Spark Connect.

Parameters
colColumn or str

target column to sort by in the descending order.

Returns
Column

the column specifying the order.

Examples

>>> df1 = spark.createDataFrame([(0, None),
...                              (1, "Bob"),
...                              (2, "Alice")], ["age", "name"])
>>> df1.sort(desc_nulls_last(df1.name)).show()
+---+-----+
|age| name|
+---+-----+
|  1|  Bob|
|  2|Alice|
|  0| null|
+---+-----+