Files
df-research/dataframe/docs/StardustDocs/topics/explode.md
2026-02-08 11:20:43 -10:00

1.8 KiB
Vendored

Splits list-like values in given columns and spreads them vertically. Values in other columns are duplicated.

explode(dropEmpty = true) [ { columns } ]

Reverse operation: implode

See column selectors for how to select the columns for this operation.

Parameters:

  • dropEmpty — if true, removes rows with empty lists or DataFrame objects. Otherwise, they will be exploded into null.

Available for:

Exploded columns will change their types:

Exploded FrameColumn will be converted into ColumnGroup.

Explode DataFrame:

val df = dataFrameOf("a", "b")(
    1, listOf(1, 2),
    2, listOf(3, 4),
)

df.explode("b")

When several columns are exploded in one operation, lists in different columns will be aligned.

val a by columnOf(listOf(1, 2), listOf(3, 4, 5))
val b by columnOf(listOf(1, 2, 3), listOf(4, 5))

val df = dataFrameOf(a, b)
df.explode { a and b }

Explode DataColumn<Collection>:

val col by columnOf(listOf(1, 2), listOf(3, 4))

col.explode()

Explode FrameColumn:

val col by columnOf(
    dataFrameOf("a", "b")(1, 2, 3, 4),
    dataFrameOf("a", "b")(5, 6, 7, 8),
)

col.explode()