You are viewing documentation about an older version (1.3.0). View latest version

snowflake.snowpark.DataFrame.orderBy¶

DataFrame.orderBy(*cols: ColumnOrName | Iterable[ColumnOrName], ascending: bool | int | List[bool | int] | None = None) → DataFrame[source]¶

Sorts a DataFrame by the specified expressions (similar to ORDER BY in SQL).

Examples:

>>> from snowflake.snowpark.functions import col

>>> df = session.create_dataframe([[1, 2], [3, 4], [1, 4]], schema=["A", "B"])
>>> df.sort(col("A"), col("B").asc()).show()
-------------
|"A"  |"B"  |
-------------
|1    |2    |
|1    |4    |
|3    |4    |
-------------


>>> df.sort(col("a"), ascending=False).show()
-------------
|"A"  |"B"  |
-------------
|3    |4    |
|1    |2    |
|1    |4    |
-------------


>>> # The values from the list overwrite the column ordering.
>>> df.sort(["a", col("b").desc()], ascending=[1, 1]).show()
-------------
|"A"  |"B"  |
-------------
|1    |2    |
|1    |4    |
|3    |4    |
-------------
Copy
Parameters:
  • *cols – A column name as str or Column, or a list of columns to sort by.

  • ascending – A bool or a list of bool for sorting the DataFrame, where True sorts a column in ascending order and False sorts a column in descending order . If you specify a list of multiple sort orders, the length of the list must equal the number of columns.