TableFrame.with_columns
methodView source ↗
def with_columns(
*exprs: td_IntoExpr | Iterable[td_IntoExpr],
**named_exprs: td_IntoExpr,
) -> TableFrame
Categories: projection
Add columns to the TableFrame.
Parameters
parameter
exprsColumns or expressions to add.
parameter
named_exprsNamed expressions to add.
Examples
>>> import tabsdata as td
>>>
>>> tf: td.TableFrame ...
>>>
┌──────┬──────┐
│ x ┆ y │
│ --- ┆ --- │
│ f64 ┆ f64 │
╞══════╪══════╡
│ 1.0 ┆ 2.0 │
│ 2.0 ┆ 2.0 │
│ 10.0 ┆ 10.0 │
│ 4.0 ┆ 10.0 │
│ 5.0 ┆ null │
│ null ┆ null │
└──────┴──────┘
>>>
>>> tf.with_columns(td.col("x").mul(td.col("y")).alias("z"))
>>>
┌──────┬──────┬──────┐
│ x ┆ y ┆ z │
│ --- ┆ --- ┆ --- │
│ f64 ┆ f64 ┆ f64 │
╞══════╪══════╪══════╡
│ 1.0 ┆ 2.0 ┆ 2.0 │
│ 2.0 ┆ 2.0 ┆ 4.0 │
│ NaN ┆ NaN ┆ NaN │
│ 4.0 ┆ NaN ┆ NaN │
│ 5.0 ┆ null ┆ null │
│ null ┆ null ┆ null │
└──────┴──────┴──────┘