daft.DataFrame.with_columns#
- DataFrame.with_columns(columns: Dict[str, Expression]) DataFrame [source]#
Adds columns to the current DataFrame with Expressions, equivalent to a
select
with all current columns and the new onesExample
>>> import daft >>> 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 }
- Returns:
DataFrame with new columns.
- Return type: