ibis.expr.api.GroupedTableExpr.mutate

GroupedTableExpr.mutate(exprs=None, **kwds)

Returns a table projection with analytic / window functions applied. Any arguments can be functions.

Parameters:
exprs : list, default None
kwds : key=value pairs
Returns:
mutated : TableExpr

Examples

>>> import ibis
>>> t = ibis.table([
...     ('foo', 'string'),
...     ('bar', 'string'),
...     ('baz', 'double'),
... ], name='t')
>>> t
UnboundTable[table]
  name: t
  schema:
    foo : string
    bar : string
    baz : double
>>> expr = (t.group_by('foo')
...          .order_by(ibis.desc('bar'))
...          .mutate(qux=lambda x: x.baz.lag(),
...                  qux2=t.baz.lead()))
>>> print(expr)  
ref_0
UnboundTable[table]
  name: t
  schema:
    foo : string
    bar : string
    baz : double
Selection[table]
  table:
    Table: ref_0
  selections:
    Table: ref_0
    qux = WindowOp[double*]
      qux = Lag[double*]
        baz = Column[double*] 'baz' from table
          ref_0
        offset:
          None
        default:
          None
      <ibis.expr.window.Window object at 0x...>
    qux2 = WindowOp[double*]
      qux2 = Lead[double*]
        baz = Column[double*] 'baz' from table
          ref_0
        offset:
          None
        default:
          None
      <ibis.expr.window.Window object at 0x...>