ibis.expr.api.TableExpr.mutate

TableExpr.mutate(exprs=None, **mutations)

Convenience function for table projections involving adding columns

Parameters:
exprs : list, default None

List of named expressions to add as columns

mutations : keywords for new columns
Returns:
mutated : TableExpr

Examples

Using keywords arguments to name the new columns

>>> import ibis
>>> table = ibis.table([('foo', 'double'), ('bar', 'double')], name='t')
>>> expr = table.mutate(qux=table.foo + table.bar, baz=5)
>>> expr  # doctest: +NORMALIZE_WHITESPACE
ref_0
UnboundTable[table]
  name: t
  schema:
    foo : double
    bar : double
<BLANKLINE>
Selection[table]
  table:
    Table: ref_0
  selections:
    Table: ref_0
    baz = Literal[int8]
      5
    qux = Add[double*]
      left:
        foo = Column[double*] 'foo' from table
          ref_0
      right:
        bar = Column[double*] 'bar' from table
          ref_0

Using the ibis.expr.types.Expr.name() method to name the new columns

>>> new_columns = [ibis.literal(5).name('baz',),
...                (table.foo + table.bar).name('qux')]
>>> expr2 = table.mutate(new_columns)
>>> expr.equals(expr2)
True