Skip to main content
GuideServerConfigure and deploy Tabsdata servers on your machine.TutorialsConfigure data integration workflows within a running Tabsdata server.Advanced TutorialsBuild end-to-end workflows between two specific systems.API ReferenceCLI ReferenceRelease Notes
Version: 2.0.0

LazyGroupBy

class
class LazyGroupBy(lgb, parent, by)

Categories: aggregation

Pending group-by over a TableFrame, produced by group_by.

Obtain one from TableFrame.group_by(...), then call .agg(...) with reducing expressions such as col("v").sum(). The reduction shortcut methods (sum / min / max / mean / median / n_unique) reduce EVERY column and can fail on a table's hidden system columns; prefer agg(col(...).<reduction>()). count and len are always safe.

Examples

tf.group_by("g").agg(col("a").mean().alias("average"))

Wrap a grouper; created by TableFrame.group_by, not directly.

Parameters

parameter
lgb

parameter
parent

parameter
by

Methods

method
agg
def agg(
*aggs: IntoExpr | Iterable[IntoExpr] = (),
**named_aggs: IntoExpr = {},
) -> TableFrame

Reduce each group to one row using the given expressions.

Each expression is a column reduction -- typically col(name) plus a reducer and an alias. The result has one row per group: the group key column(s) followed by the aggregated columns.

Parameters:

parameter
*aggsIntoExpr | Iterable[IntoExpr] (int | float | Decimal | date | time | datetime | timedelta | str | bool | bytes | list[Any] | Expr | str | None | Iterable[int | float | Decimal | date | time | datetime | timedelta | str | bool | bytes | list[Any] | Expr | str | None])

Aggregation expressions to compute per group.

parameter
**named_aggsIntoExpr (int | float | Decimal | date | time | datetime | timedelta | str | bool | bytes | list[Any] | Expr | str | None)

Aggregation expressions as keyword arguments, where the keyword names the output column.

Example:

tf.group_by("k").agg(col("v").sum().alias("s"))
tf.group_by("k").agg(col("v").mean().alias("m"))

method
len
def len(name: str | None = None) -> TableFrame

Count the rows in each group.

Safe on any TableFrame (it counts rows, not column values).

Parameters:

parameter
namestr | None

Name for the count column (default "len").

Example:

tf.group_by("g").len()

Name the output column to keep it distinct from the data:

tf.group_by("g").len("rows")

method
count
def count() -> TableFrame

Count the non-null values of each column within each group.

Yields one count column per non-key column. Safe on any TableFrame (it counts values, not reduces them).

Example:

tf.group_by("g").count()

method
max
def max() -> TableFrame

Take the maximum of each non-key column within each group.

Reduces EVERY column; may fail on a table's hidden system columns through storage. Prefer agg(col(...).max()).

Example:

tf.group_by("g").agg(col("a").max().alias("largest"))

method
mean
def mean() -> TableFrame

Average each non-key column within each group.

Reduces EVERY column; may fail on a table's hidden system columns through storage. Prefer agg(col(...).mean()).

Example:

tf.group_by("g").agg(col("a").mean().alias("average"))

method
median
def median() -> TableFrame

Take the median of each non-key column within each group.

Reduces EVERY column; may fail on a table's hidden system columns through storage. Prefer agg(col(...).median()).

Example:

tf.group_by("g").agg(col("a").median().alias("middle"))

method
min
def min() -> TableFrame

Take the minimum of each non-key column within each group.

Reduces EVERY column; may fail on a table's hidden system columns through storage. Prefer agg(col(...).min()).

Example:

tf.group_by("g").agg(col("a").min().alias("smallest"))

method
n_unique
def n_unique() -> TableFrame

Count the distinct values of each non-key column within each group.

Reduces EVERY column; may fail on a table's hidden system columns through storage. Prefer agg(col(...).n_unique()).

Example:

tf.group_by("g").agg(col("a").n_unique().alias("distinct"))

method
sum
def sum() -> TableFrame

Sum each non-key column within each group.

Reduces EVERY column; may fail on a table's hidden system columns through storage. Prefer agg(col(...).sum()).

Example:

tf.group_by("g").agg(col("a").sum().alias("total"))