pyspark.sql.functions.
asc
Returns a sort expression based on the ascending order of the given column name.
New in version 1.3.0.
Changed in version 3.4.0: Supports Spark Connect.
Column
target column to sort by in the ascending order.
the column specifying the order.
Examples
Sort by the column ‘id’ in the descending order.
>>> df = spark.range(5) >>> df = df.sort(desc("id")) >>> df.show() +---+ | id| +---+ | 4| | 3| | 2| | 1| | 0| +---+
Sort by the column ‘id’ in the ascending order.
>>> df.orderBy(asc("id")).show() +---+ | id| +---+ | 0| | 1| | 2| | 3| | 4| +---+