ibis.expr.api.TableExpr.mutate¶
-
TableExpr.
mutate
(exprs: Optional[List[ibis.expr.types.Expr]] = None, **mutations: Any) → ibis.expr.types.TableExpr¶ 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
- Return type
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 ref_0 UnboundTable[table] name: t schema: foo : float64 bar : float64 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