GroupedTable

GroupedTable(**kwargs)

An intermediate table expression to hold grouping information.

Methods

Name Description
aggregate Compute aggregates over a group by.
count Computing the number of rows per group.
having Add a post-aggregation result filter expr.
mutate Return a table projection with window functions applied.
order_by Sort a grouped table expression by expr.
over Apply a window over the input expressions.
select Project new columns out of the grouped table.

aggregate

aggregate(*metrics, **kwds)

Compute aggregates over a group by.

count

count()

Computing the number of rows per group.

Returns

Name Type Description
Table The aggregated table

having

having(*predicates)

Add a post-aggregation result filter expr.

Expressions like x is None return bool and will not generate a SQL comparison to NULL

Parameters

Name Type Description Default
predicates ir.BooleanScalar Expressions that filters based on an aggregate value. ()

Returns

Name Type Description
GroupedTable A grouped table expression

mutate

mutate(*exprs, **kwexprs)

Return a table projection with window functions applied.

Any arguments can be functions.

Parameters

Name Type Description Default
exprs ir.Value | Sequence[ir.Value] List of expressions ()
kwexprs ir.Value Expressions {}

Examples

>>> import ibis
>>> import ibis.selectors as s
>>> ibis.options.interactive = True
>>> t = ibis.examples.penguins.fetch()
>>> t
┏━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━┓
┃ species  island     bill_length_mm  bill_depth_mm  flipper_length_mm  body_mass_g  sex     year  ┃
┡━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━┩
│ stringstringfloat64float64int64int64stringint64 │
├─────────┼───────────┼────────────────┼───────────────┼───────────────────┼─────────────┼────────┼───────┤
│ Adelie Torgersen39.118.71813750male  2007 │
│ Adelie Torgersen39.517.41863800female2007 │
│ Adelie Torgersen40.318.01953250female2007 │
│ Adelie TorgersenNULLNULLNULLNULLNULL2007 │
│ Adelie Torgersen36.719.31933450female2007 │
│ Adelie Torgersen39.320.61903650male  2007 │
│ Adelie Torgersen38.917.81813625female2007 │
│ Adelie Torgersen39.219.61954675male  2007 │
│ Adelie Torgersen34.118.11933475NULL2007 │
│ Adelie Torgersen42.020.21904250NULL2007 │
│  │
└─────────┴───────────┴────────────────┴───────────────┴───────────────────┴─────────────┴────────┴───────┘
>>> (
...     t.select("species", "bill_length_mm")
...     .group_by("species")
...     .mutate(centered_bill_len=ibis._.bill_length_mm - ibis._.bill_length_mm.mean())
...     .order_by(s.all())
... )
┏━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┓
┃ species  bill_length_mm  centered_bill_len ┃
┡━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━┩
│ stringfloat64float64           │
├─────────┼────────────────┼───────────────────┤
│ Adelie 32.1-6.691391 │
│ Adelie 33.1-5.691391 │
│ Adelie 33.5-5.291391 │
│ Adelie 34.0-4.791391 │
│ Adelie 34.1-4.691391 │
│ Adelie 34.4-4.391391 │
│ Adelie 34.5-4.291391 │
│ Adelie 34.6-4.191391 │
│ Adelie 34.6-4.191391 │
│ Adelie 35.0-3.791391 │
│  │
└─────────┴────────────────┴───────────────────┘

Returns

Name Type Description
Table A table expression with window functions applied

order_by

order_by(*by)

Sort a grouped table expression by expr.

Notes

This API call is ignored in aggregations.

Parameters

Name Type Description Default
by ir.Value Expressions to order the results by ()

Returns

Name Type Description
GroupedTable A sorted grouped GroupedTable

over

over(window=None, *, rows=None, range=None, group_by=None, order_by=None)

Apply a window over the input expressions.

Parameters

Name Type Description Default
window Window to add to the input None
rows Whether to use the ROWS window clause None
range Whether to use the RANGE window clause None
group_by Grouping key None
order_by Ordering key None

Returns

Name Type Description
GroupedTable A new grouped table expression

select

select(*exprs, **kwexprs)

Project new columns out of the grouped table.

See Also

GroupedTable.mutate