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

>>> df = daft.from_pydict({
>>>     "x": [[1], [2, 3]],
>>>     "y": [["a"], ["b", "c"]],
>>>     "z": [1.0, 2.0],
>>> ]})
>>>
>>> df.explode(col("x"), col("y"))
>>>
>>> # +------+-----------+-----+      +------+------+-----+
>>> # | x    | y         | z   |      |  x   |  y   | z   |
>>> # +------+-----------+-----+      +------+------+-----+
>>> # |[1]   | ["a"]     | 1.0 |      |  1   | "a"  | 1.0 |
>>> # +------+-----------+-----+  ->  +------+------+-----+
>>> # |[2, 3]| ["b", "c"]| 2.0 |      |  2   | "b"  | 2.0 |
>>> # +------+-----------+-----+      +------+------+-----+
>>> # |[]    | []        | 3.0 |      |  3   | "c"  | 2.0 |
>>> # +------+-----------+-----+      +------+------+-----+
>>> # |None  | None      | 4.0 |      | None | None | 3.0 |
>>> # +------+-----------+-----+      +------+------+-----+
>>> #                                 | None | None | 4.0 |
>>> #                                 +------+------+-----+
Parameters:

*columns (ColumnInputType) – columns to explode

Returns:

DataFrame with exploded column

Return type:

DataFrame