daft.DataFrame.with_column#
- DataFrame.with_column(column_name: str, expr: Expression) DataFrame [source]#
Adds a column to the current DataFrame with an Expression, equivalent to a
select
with all current columns and the new oneExample
>>> import daft >>> df = daft.from_pydict({"x": [1, 2, 3]}) >>> new_df = df.with_column('x+1', col('x') + 1) >>> new_df.show() ╭───────┬───────╮ │ x ┆ x+1 │ │ --- ┆ --- │ │ Int64 ┆ Int64 │ ╞═══════╪═══════╡ │ 1 ┆ 2 │ ├╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤ │ 2 ┆ 3 │ ├╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤ │ 3 ┆ 4 │ ╰───────┴───────╯ (Showing first 3 of 3 rows)
- Parameters:
column_name (str) – name of new column
expr (Expression) – expression of the new column.
- Returns:
DataFrame with new column.
- Return type: