daft.DataFrame.with_columns#
- DataFrame.with_columns(columns: ~typing.Dict[str, ~daft.expressions.expressions.Expression], resource_request: ~daft.daft.ResourceRequest = ResourceRequest { num_cpus: None, num_gpus: None, memory_bytes: None }) DataFrame [source]#
Adds columns to the current DataFrame with Expressions, equivalent to a
select
with all current columns and the new onesExample
>>> df = daft.from_pydict({'x': [1, 2, 3], 'y': [4, 5, 6]}) >>> >>> new_df = df.with_columns({ 'foo': df['x'] + 1, 'bar': df['y'] - df['x'] })
>>> new_df.show() ╭───────┬───────┬───────┬───────╮ │ x ┆ y ┆ foo ┆ bar │ │ --- ┆ --- ┆ --- ┆ --- │ │ Int64 ┆ Int64 ┆ Int64 ┆ Int64 │ ╞═══════╪═══════╪═══════╪═══════╡ │ 1 ┆ 4 ┆ 2 ┆ 3 │ ├╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤ │ 2 ┆ 5 ┆ 3 ┆ 3 │ ├╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤ │ 3 ┆ 6 ┆ 4 ┆ 3 │ ╰───────┴───────┴───────┴───────╯ (Showing first 3 of 3 rows)
- Parameters:
columns (Dict[str, Expression]) – Dictionary of new columns in the format { name: expression }
resource_request (ResourceRequest) – a custom resource request for the execution of this operation
- Returns:
DataFrame with new columns.
- Return type: