TableFrame.group_by
methodView source ↗
def group_by(*by: IntoTdExpr | Iterable[IntoTdExpr]) -> TdLazyGroupBy
Categories: aggregation
Perform a group by on the TableFrame.
Parameters
parameter
byColumns or expressions to group by.
Examples
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
┌─────┬─────┐
│ a ┆ b │
│ --- ┆ --- │
│ str ┆ i64 │
╞═════╪═════╡
│ A ┆ 1 │
│ X ┆ 10 │
│ C ┆ 3 │
│ D ┆ 5 │
│ M ┆ 9 │
│ A ┆ 100 │
│ M ┆ 50 │
└─────┴─────┘
>>>
>>> tf.group_by(td.col("a")).agg(td.col("b").sum())
>>>
┌─────┬─────┐
│ a ┆ b │
│ --- ┆ --- │
│ str ┆ i64 │
╞═════╪═════╡
│ M ┆ 59 │
│ A ┆ 101 │
│ C ┆ 3 │
│ D ┆ 5 │
│ X ┆ 10 │
└─────┴─────┘