pyspark.sql.Column.desc_nulls_first

Column.desc_nulls_first() → pyspark.sql.column.Column

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

Examples

>>> from pyspark.sql import Row
>>> df = spark.createDataFrame([('Tom', 80), (None, 60), ('Alice', None)], ["name", "height"])
>>> df.select(df.name).orderBy(df.name.desc_nulls_first()).collect()
[Row(name=None), Row(name='Tom'), Row(name='Alice')]