diff --git a/docs/src/python/user-guide/expressions/aggregation.py b/docs/src/python/user-guide/expressions/aggregation.py index f2d75cbd3726..f67226fdc3d7 100644 --- a/docs/src/python/user-guide/expressions/aggregation.py +++ b/docs/src/python/user-guide/expressions/aggregation.py @@ -160,9 +160,7 @@ def get_person() -> pl.Expr: get_person().first().alias("youngest"), get_person().last().alias("oldest"), get_person().sort().first().alias("alphabetical_first"), - pl.col("gender") - .sort_by(pl.col("first_name").cast(pl.Categorical("lexical"))) - .first(), + pl.col("gender").sort_by(get_person()).first(), ) .sort("state") .limit(5) diff --git a/docs/user-guide/expressions/aggregation.md b/docs/user-guide/expressions/aggregation.md index 2a036ed82322..f4d963606ffb 100644 --- a/docs/user-guide/expressions/aggregation.md +++ b/docs/user-guide/expressions/aggregation.md @@ -17,9 +17,8 @@ Per GROUP `"first_name"` we - count the number of rows in the group: - - short form: `pl.count("party")` - - full form: `pl.col("party").count()` -- aggregate the gender values groups: + - full form: `pl.len()` +- combine the values of gender into a list by omitting an aggregate function: - full form: `pl.col("gender")` - get the first value of column `"last_name"` in the group: - short form: `pl.first("last_name")` (not available in Rust) @@ -94,7 +93,7 @@ However, **if** we also want to sort the names alphabetically, this breaks. Luck --8<-- "python/user-guide/expressions/aggregation.py:sort2" ``` -We can even sort by another column in the `group_by` context. If we want to know if the alphabetically sorted name is male or female we could add: `pl.col("gender").sort_by("first_name").first().alias("gender")` +We can even sort by another column in the `group_by` context. If we want to know if the alphabetically sorted name is male or female we could add: `pl.col("gender").sort_by(get_person()).first()` {{code_block('user-guide/expressions/aggregation','sort3',['group_by'])}}