pyspark.sql.functions.asc

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

返回基于给定列名升序的排序表达式。

新增于版本 1.3.0。

在版本 3.4.0 中更改: 支持 Spark Connect。

Parameters
col Column or str

目标列按升序排序。

Returns
Column

指定顺序的列。

示例

按列‘id’降序排序。

>>> df = spark.range(5)
>>> df = df.sort(desc("id"))
>>> df.show()
+---+
| id|
+---+
|  4|
|  3|
|  2|
|  1|
|  0|
+---+

按列‘id’升序排序。

>>> df.orderBy(asc("id")).show()
+---+
| id|
+---+
|  0|
|  1|
|  2|
|  3|
|  4|
+---+