An intermediate table expression to hold grouping information.
Methods
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
Computing the number of rows per group.
Returns
|
Table |
The aggregated table |
having
Add a post-aggregation result filter expr
.
Parameters
predicates |
ir.BooleanScalar |
Expressions that filters based on an aggregate value. |
() |
mutate
mutate(*exprs, **kwexprs)
Return a table projection with window functions applied.
Any arguments can be functions.
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 ┃
┡━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━┩
│ string │ string │ float64 │ float64 │ int64 │ int64 │ string │ int64 │
├─────────┼───────────┼────────────────┼───────────────┼───────────────────┼─────────────┼────────┼───────┤
│ Adelie │ Torgersen │ 39.1 │ 18.7 │ 181 │ 3750 │ male │ 2007 │
│ Adelie │ Torgersen │ 39.5 │ 17.4 │ 186 │ 3800 │ female │ 2007 │
│ Adelie │ Torgersen │ 40.3 │ 18.0 │ 195 │ 3250 │ female │ 2007 │
│ Adelie │ Torgersen │ NULL │ NULL │ NULL │ NULL │ NULL │ 2007 │
│ Adelie │ Torgersen │ 36.7 │ 19.3 │ 193 │ 3450 │ female │ 2007 │
│ Adelie │ Torgersen │ 39.3 │ 20.6 │ 190 │ 3650 │ male │ 2007 │
│ Adelie │ Torgersen │ 38.9 │ 17.8 │ 181 │ 3625 │ female │ 2007 │
│ Adelie │ Torgersen │ 39.2 │ 19.6 │ 195 │ 4675 │ male │ 2007 │
│ Adelie │ Torgersen │ 34.1 │ 18.1 │ 193 │ 3475 │ NULL │ 2007 │
│ Adelie │ Torgersen │ 42.0 │ 20.2 │ 190 │ 4250 │ NULL │ 2007 │
│ … │ … │ … │ … │ … │ … │ … │ … │
└─────────┴───────────┴────────────────┴───────────────┴───────────────────┴─────────────┴────────┴───────┘
>>> (
... 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 ┃
┡━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━┩
│ string │ float64 │ float64 │
├─────────┼────────────────┼───────────────────┤
│ 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
|
Table |
A table expression with window functions applied |
order_by
Sort a grouped table expression by expr
.
Notes
This API call is ignored in aggregations.
Parameters
by |
ir.Value |
Expressions to order the results by |
() |
over
over(window=None, *, rows=None, range=None, group_by=None, order_by=None)
Apply a window over the input expressions.
Parameters
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 |
select
select(*exprs, **kwexprs)
Project new columns out of the grouped table.