daft.DataFrame.explode

daft.DataFrame.explode#

DataFrame.explode(*columns: Union[Expression, str]) DataFrame[source]#

Explodes a List column, where every element in each row’s List becomes its own row, and all other columns in the DataFrame are duplicated across rows

If multiple columns are specified, each row must contain the same number of items in each specified column.

Exploding Null values or empty lists will create a single Null entry (see example below).

Example

>>> import daft
>>> df = daft.from_pydict(
...     {
...         "x": [[1], [2, 3]],
...         "y": [["a"], ["b", "c"]],
...         "z": [
...             [1.0],
...             [2.0, 2.0],
...         ],
...     }
... )
>>> df.explode(col("x"), col("y")).collect()
╭───────┬──────┬───────────────╮
│ x     ┆ y    ┆ z             │
│ ---   ┆ ---  ┆ ---           │
│ Int64 ┆ Utf8 ┆ List[Float64] │
╞═══════╪══════╪═══════════════╡
│ 1     ┆ a    ┆ [1]           │
├╌╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 2     ┆ b    ┆ [2, 2]        │
├╌╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ 3     ┆ c    ┆ [2, 2]        │
╰───────┴──────┴───────────────╯

(Showing first 3 of 3 rows)
Parameters:

*columns (ColumnInputType) – columns to explode

Returns:

DataFrame with exploded column

Return type:

DataFrame