explode

fun <T> DataFrame<T>.explode(dropEmpty: Boolean = true, selector: ColumnsSelector<T, *> = defaultExplodeColumns): DataFrame<T>

Splits list-like values in the specified columns and spreads them vertically — that is, it adds a separate row for each element (one value per row). Values in all other columns are duplicated to preserve row context.

If no columns are specified, all columns (at any depth) containing List or DataFrame values will be exploded.

If dropEmpty is true, rows with empty lists or DataFrames will be removed. If false, such rows will be exploded into null values.

Returns a new DataFrame with exploded columns.

Each exploded column will have a new type (List<T> ->T). When several columns are exploded in one operation, lists in different columns will be aligned.

This operation is the reverse of implode.

This can include column groups and nested columns.

For more information, see: See explode on the documentation website.

This explode overload

Select or express columns using the Columns Selection DSL.

This DSL is initiated by a Columns Selector lambda, which operates in the context of the Columns Selection DSL and expects you to return a SingleColumn or ColumnSet (so, a ColumnsResolver). This is an entity formed by calling any (combination) of the functions in the DSL that is or can be resolved into one or more columns.

The Columns Selection DSL allows using Extension Properties for specifying columns type- and name-safe.

Check out: Columns Selection DSL Grammar

    

See Column Selectors on the documentation website.

Examples

// Explodes all `List` and `DataFrame` columns at any depth
df.explode()

// Explodes the "tags" column of type `List<String>`
df.explode { tags }

// Explodes all columns of type `List<Double>`
df.explode { colsOf<List<Double>>() }

Return

A new DataFrame with exploded columns.

Parameters

dropEmpty

If true, removes rows with empty Lists or DataFrames. If false, such rows will be exploded into null values.

selector

The ColumnsSelector used to select columns to explode. If not specified, all applicable columns (i.e., of type List or DataFrame) will be exploded.

Throws

if the specified columns are not of type List or DataFrame.


fun <T> DataFrame<T>.explode(vararg columns: String, dropEmpty: Boolean = true): DataFrame<T>

Splits list-like values in the specified columns and spreads them vertically — that is, it adds a separate row for each element (one value per row). Values in all other columns are duplicated to preserve row context.

If no columns are specified, all columns (at any depth) containing List or DataFrame values will be exploded.

If dropEmpty is true, rows with empty lists or DataFrames will be removed. If false, such rows will be exploded into null values.

Returns a new DataFrame with exploded columns.

Each exploded column will have a new type (List<T> ->T). When several columns are exploded in one operation, lists in different columns will be aligned.

This operation is the reverse of implode.

This can include column groups and nested columns.

For more information, see: See explode on the documentation website.

This explode overload

Select single or multiple columns using their names as Strings. (String API).

Example

// Explodes the "tags" and "scores" columns, where
// "tags" is a `List<String>` and "scores" is a `List<Int>`
val exploded = df.explode("tags", "scores")

Return

A new DataFrame with exploded columns.

Parameters

dropEmpty

If true, removes rows with empty Lists or DataFrames. If false, such rows will be exploded into null values.

columns

The column names used to select columns to explode. If not specified, all applicable columns (i.e., of type List or DataFrame) will be exploded.

Throws

if the specified columns are not of type List or DataFrame.


fun <T> DataRow<T>.explode(dropEmpty: Boolean = true, columns: ColumnsSelector<T, *> = defaultExplodeColumns): DataFrame<T>

Splits list-like values in the specified columns of this DataRow and spreads them vertically — that is, it adds a separate row for each element (one value per row) and combines them into a new DataFrame. Values in all other columns are duplicated to preserve row context.

If no columns are specified, all columns (at any depth) containing List or DataFrame values will be exploded.

If dropEmpty is true, the result will exclude rows with empty lists or DataFrames. If false, such values will be exploded into null.

Returns a new DataFrame expanded into multiple rows based on the exploded columns.

Each exploded column will have a new type (List<T> → T). When several columns are exploded in one operation, lists in different columns will be aligned.

This can include column groups and nested columns.

For more information, see: See explode on the documentation website.

This explode overload

Select or express columns using the Columns Selection DSL.

This DSL is initiated by a Columns Selector lambda, which operates in the context of the Columns Selection DSL and expects you to return a SingleColumn or ColumnSet (so, a ColumnsResolver). This is an entity formed by calling any (combination) of the functions in the DSL that is or can be resolved into one or more columns.

The Columns Selection DSL allows using Extension Properties for specifying columns type- and name-safe.

Check out: Columns Selection DSL Grammar

    

See Column Selectors on the documentation website.

Example

// Explodes the `hobbies` and `scores` values of the row,
// of types `List<String>` and `List<Int>`, respectively
row.explode { hobbies and scores }

Return

A new DataFrame with exploded columns from this DataRow.

Parameters

dropEmpty

If true, removes rows with empty Lists or DataFrames. If false, such rows will be exploded into null values.

columns

The ColumnsSelector used to select columns to explode. If not specified, all applicable columns (i.e., of type List or DataFrame) will be exploded.

Throws

if the specified columns are not of type List or DataFrame.


fun <T> DataRow<T>.explode(vararg columns: String, dropEmpty: Boolean = true): DataFrame<T>

Splits list-like values in the specified columns of this DataRow and spreads them vertically — that is, it adds a separate row for each element (one value per row) and combines them into a new DataFrame. Values in all other columns are duplicated to preserve row context.

If no columns are specified, all columns (at any depth) containing List or DataFrame values will be exploded.

If dropEmpty is true, the result will exclude rows with empty lists or DataFrames. If false, such values will be exploded into null.

Returns a new DataFrame expanded into multiple rows based on the exploded columns.

Each exploded column will have a new type (List<T> → T). When several columns are exploded in one operation, lists in different columns will be aligned.

This can include column groups and nested columns.

For more information, see: See explode on the documentation website.

This explode overload

Select single or multiple columns using their names as Strings. (String API).

Example

// Explodes the `hobbies` and `scores` values of the row,
// of types `List<String>` and `List<Int>`, respectively
row.explode("hobbies", "scores")

Return

A new DataFrame with exploded columns from this DataRow.

Parameters

dropEmpty

If true, removes rows with empty Lists or DataFrames. If false, such rows will be exploded into null values.

columns

The column names used to select columns to explode. If not specified, all applicable columns (i.e., of type List or DataFrame) will be exploded.

Throws

if the specified columns are not of type List or DataFrame.


@JvmName(name = "explodeList")
fun <T> DataColumn<Collection<T>>.explode(): DataColumn<T>

Splits list-like values in this DataColumn and spreads them vertically — that is, it adds a separate row for each element (one value per row).

Returns a new DataColumn with the exploded values. The resulting column will have a new type (List<T> → T).

For more information, see: See explode on the documentation website.

Return

A new DataColumn with exploded values.


@JvmName(name = "explodeFrames")
fun <T> DataColumn<DataFrame<T>>.explode(): ColumnGroup<T>

Explodes a DataColumn of DataFrame values into a single ColumnGroup.

Each nested DataFrame is unwrapped, and its columns are placed side by side within a column group named after the original column. The number of resulting rows equals the total number of rows across all nested DataFrames.

For more information, see: See explode on the documentation website.

Return

A ColumnGroup containing the concatenated contents of all nested DataFrames.


fun <T, C> DataFrame<T>.explode(vararg columns: ColumnReference<C>, dropEmpty: Boolean = true): DataFrame<T>
fun <T, C> DataFrame<T>.explode(vararg columns: KProperty<C>, dropEmpty: Boolean = true): DataFrame<T>
fun <T, C> DataRow<T>.explode(vararg columns: ColumnReference<C>, dropEmpty: Boolean = true): DataFrame<T>
fun <T, C> DataRow<T>.explode(vararg columns: KProperty<C>, dropEmpty: Boolean = true): DataFrame<T>

Deprecated

It's recommended to migrate to the String or Extension Properties Access API https://kotlin.github.io/dataframe/apilevels.html