ibis.expr.api.TableExpr.mutate

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

Convenience function for table projections involving adding columns

Parameters
exprslist, default None

List of named expressions to add as columns

mutationskeywords for new columns
Returns
mutatedTableExpr

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 : float64
    bar : float64
<BLANKLINE>
Selection[table]
  table:
    Table: ref_0
  selections:
    Table: ref_0
    baz = Literal[int8]
      5
    qux = Add[float64*]
      left:
        foo = Column[float64*] 'foo' from table
          ref_0
      right:
        bar = Column[float64*] '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