daft.DataFrame.transform

daft.DataFrame.transform#

DataFrame.transform(func: Callable[[...], DataFrame], *args: Any, **kwargs: Any) DataFrame[source]#

Apply a function that takes and returns a DataFrame. Allow splitting your transformation into different units of work (functions) while preserving the syntax for chaining transformations.

Example

>>> import daft
>>> df = daft.from_pydict({"col_a":[1,2,3,4]})
>>> def add_1(df):
...     df = df.select(daft.col("col_a") + 1)
...     return df
...
>>> def multiply_x(df, x):
...     df = df.select(daft.col("col_a") * x)
...     return df
...
>>> df = df.transform(add_1).transform(multiply_x, 4)
>>> df.show()
╭───────╮
│ col_a │
│ ---   │
│ Int64 │
╞═══════╡
│ 8     │
├╌╌╌╌╌╌╌┤
│ 12    │
├╌╌╌╌╌╌╌┤
│ 16    │
├╌╌╌╌╌╌╌┤
│ 20    │
╰───────╯

(Showing first 4 of 4 rows)
Parameters:
  • func – A function that takes and returns a DataFrame.

  • *args – Positional arguments to pass to func.

  • **kwargs – Keyword arguments to pass to func.

Returns:

Transformed DataFrame.

Return type:

DataFrame