pyspark.sql.functions.asc_nulls_first

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

Returns a sort expression based on the ascending order of the given column name, and null values return before 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 ascending order.

Returns
Column

the column specifying the order.

Examples

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