snowflake.snowpark.DataFrame.order_by¶
- DataFrame.order_by(*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 | -------------
- Parameters:
*cols – A column name as
str
orColumn
, or a list of columns to sort by.ascending – A
bool
or a list ofbool
for sorting the DataFrame, whereTrue
sorts a column in ascending order andFalse
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.