sortByDesc
Sorts this DataFrame rows by the specified columns in ascending or descending (default) order.
Returns a new DataFrame containing the same rows, sorted according to the selected columns.
Select columns to sort by, adjust sorting order and nulls position using SortDsl.
The Sort DSL allows selecting columns to sort rows by values in these columns. It also allows reversing the sort order for individual columns or column sets, and controlling the position of null values.
The order in which columns are selected determines the sort priority.
By default, all selected columns are sorted in the original order (ascending in sortBy and descending in sortByDesc). Use reversed to impose the reverse ordering for a column or column set.
By default, null values are considered the smallest values when sorting. Use nullsLast to treat them as the largest values.
See also
sortBythat sorts rows in ascending order by default.sortWiththat sorts rows using a custom comparator.
Examples
// Sort rows by "age" column values descending
df.sortByDesc { age }
// Sort rows by "age" column values descending
// and then by the ("name"/"firstName") column values ascending
df.sortByDesc { age and name.firstName.reversed() }
// Sort rows by "weight" column values descending with nulls first
df.sortByDesc { weight.nullsLast() }Sorting values can also be computed inline using expr.
// Sort rows by the product of "volume" and "quantity" descending
df.sortByDesc { expr { volume * quantity } }Return
A new DataFrame with the original rows sorted based on the specified columns and directions.
Parameters
The Sort Columns Selector that defines which columns are used for sorting, in which order and direction.
Sorts this DataFrame rows by the specified columns in descending order.
Returns a new DataFrame containing the same rows, sorted according to the selected columns.
Select single or multiple columns using their names as Strings. (String API).
The order in which columns are selected determines the sort priority.
See also
overload that usessortByDesc { }SortDslfor selecting columns, allowing specifying sort directions andnulls position.sortBythat sorts rows in ascending order.sortWiththat sorts rows using a custom comparator.
Examples
df.sortByDesc("age")
// Sort rows by "age" column values descending
// and then by the ("name") column values descending
df.sortByDesc("age", "name")Return
A new DataFrame with the original rows sorted based on the specified columns.
Parameters
The Column Names that defines which columns are used for sorting.
Sorts rows within each group of this GroupBy by the specified columns in descending order.
Returns a new GroupBy containing the same keys and groups, with rows sorted within each group according to the selected columns.
Don't confuse this with sortByGroup, sortByCount, and sortByKey, which sort key-group pairs instead.
Select single or multiple columns using their names as Strings. (String API).
The order in which columns are selected determines the sort priority.
See also
overload that usessortByDesc { }SortDslfor selecting columns, allowing specifying sort directions andnulls position.sortBythat sorts rows in ascending order.sortByGroupandsortByGroupDescthat sort key-group pairs by values computed for each group.sortByCountandsortByCountAscthat sort key-group pairs by group size.sortByKeyandsortByKeyDescthat sort key-group pairs by key values.
Check out .GroupBy grammar
For more information: See "GroupBy Transformation" on the documentation website.
Examples
gb.sortByDesc("age")
// Sort group rows by "age" column values descending
// and then by the ("name") column values descending
gb.sortByDesc("age", "name")Return
A new GroupBy with rows sorted within each group and the original key-group order preserved.
Parameters
The Column Names that define which columns are used for sorting.
Throws
if a referenced column cannot be resolved in a group.
Sorts rows within each group of this GroupBy by the specified columns in ascending or descending (default) order.
Returns a new GroupBy containing the same keys and groups, with rows sorted within each group according to the selected columns.
Don't confuse this with sortByGroup, sortByCount, and sortByKey, which sort key-group pairs instead.
Select columns to sort by, adjust sorting order and nulls position using SortDsl.
The Sort DSL allows selecting columns to sort rows by values in these columns. It also allows reversing the sort order for individual columns or column sets, and controlling the position of null values.
The order in which columns are selected determines the sort priority.
By default, all selected columns are sorted in the original order (ascending in sortBy and descending in sortByDesc). Use reversed to impose the reverse ordering for a column or column set.
By default, null values are considered the smallest values when sorting. Use nullsLast to treat them as the largest values.
See also
sortBythat sorts rows in ascending order by default.sortByGroupandsortByGroupDescthat sort key-group pairs by values computed for each group.sortByCountandsortByCountAscthat sort key-group pairs by group size.sortByKeyandsortByKeyDescthat sort key-group pairs by key values.
Check out .GroupBy grammar
For more information: See "GroupBy Transformation" on the documentation website.
Examples
// Sort group rows by "age" column values descending
gb.sortByDesc { age }
// Sort group rows by "age" column values ase
// and then by the ("name"/"firstName") column values ascending
gb.sortByDesc { age and name.firstName.reversed() }
// Sort group rows by "weight" column values descending with nulls first
gb.sortByDesc { weight.nullsLast() }Sorting values can also be computed inline using expr.
// Sort rows by the product of "volume" and "quantity" descending
gb.sortByDesc { expr { volume * quantity } }Return
A new GroupBy with rows sorted within each group and the original key-group order preserved.
Parameters
The Sort Columns Selector that defines which columns are used for sorting within each group, in which order and direction.
Throws
if a referenced column cannot be resolved in a group.
Deprecated
It's recommended to migrate to the String or Extension Properties Access API https://kotlin.github.io/dataframe/apilevels.html