snowflake.snowpark.DataFrame.order_by¶
- DataFrame.order_by(*cols: Union[Column, str, Iterable[Union[Column, str]]], ascending: Optional[Union[bool, int, List[Union[bool, int]]]] = None) DataFrame[source] (https://github.com/snowflakedb/snowpark-python/blob/v1.30.0/snowpark-python/src/snowflake/snowpark/dataframe.py#L1866-L2003)¶
- 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 - stror- Column, or a list of columns to sort by.
- ascending – A - boolor a list of- boolfor sorting the DataFrame, where- Truesorts a column in ascending order and- Falsesorts 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.