implode
Merges all values of every column of this DataFrame into a single DataRow.
Each value of the resulting row is a List of all values in the corresponding column. A ColumnGroup is converted into a DataFrame containing its rows.
If dropNA is true, values are removed from the merged lists of value columns.NA
It is the same as df.implode(dropNA) { all() }.single().
Reverse operation: explode.
For more information: See implode on the documentation website.
Example
The examples below use this DataFrame:
| name | age | city |
|---|---|---|
| Alice | 15 | London |
| Alice | 15 | Milan |
| Bob | 45 | Tokyo |
| Bob | 45 | null |
// Merges all values of every column into a single row of lists
val row = df.implode()| name | age | city |
|---|---|---|
[Alice, Alice, Bob, Bob] | [15, 15, 45, 45] | [London, Milan, Tokyo, null] |
Return
A DataRow with all values of every column merged into lists.
Parameters
If true, values (NAnull, Double.NaN or Float.NaN) are removed from the merged lists. false by default. Has no effect on imploded column groups and frame columns. Values are removed from each imploded column independently, so when several columns are imploded at once, their lists may stop lining up by position, and explode will not restore the original rows.
Type Parameters
The schema marker type of this DataFrame.
Merges values in the specified columns into lists, grouped by the values in all other columns — that is, rows with equal values in the other columns are collapsed into a single row.
The other columns are used as grouping keys and keep their types.
If dropNA is true, values are removed from the merged lists of value columns.NA
Imploded columns will change their types:
An imploded ColumnGroup is converted into a FrameColumn.
Reverse operation: explode.
This can include column groups and nested columns.
For more information: See implode on the documentation website.
This implode 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
The examples below use this DataFrame:
| name | age | city |
|---|---|---|
| Alice | 15 | London |
| Alice | 15 | Milan |
| Bob | 45 | Tokyo |
| Bob | 45 | null |
// Merges the "city" values of each person into a list,
// one row per distinct "name" and "age"
df.implode { city }| name | age | city |
|---|---|---|
| Alice | 15 | [London, Milan] |
| Bob | 45 | [Tokyo, null] |
// Same as above, but `null` cities are removed from the lists
df.implode(dropNA = true) { city }| name | age | city |
|---|---|---|
| Alice | 15 | [London, Milan] |
| Bob | 45 | [Tokyo] |
Return
A new DataFrame with one row per distinct combination of values in the other columns, where the specified columns contain merged lists of values.
Parameters
If true, values (NAnull, Double.NaN or Float.NaN) are removed from the merged lists. false by default. Has no effect on imploded column groups and frame columns. Values are removed from each imploded column independently, so when several columns are imploded at once, their lists may stop lining up by position, and explode will not restore the original rows.
The ColumnsSelector used to select columns to implode.
Type Parameters
The schema marker type of this DataFrame.
The common type of the selected columns.
Merges values in the specified columns into lists, grouped by the values in all other columns — that is, rows with equal values in the other columns are collapsed into a single row.
The other columns are used as grouping keys and keep their types.
If dropNA is true, values are removed from the merged lists of value columns.NA
Imploded columns will change their types:
An imploded ColumnGroup is converted into a FrameColumn.
Reverse operation: explode.
This can include column groups and nested columns.
For more information: See implode on the documentation website.
This implode overload
Select single or multiple columns using their names as Strings. (String API).
Examples
The examples below use this DataFrame:
| name | age | city |
|---|---|---|
| Alice | 15 | London |
| Alice | 15 | Milan |
| Bob | 45 | Tokyo |
| Bob | 45 | null |
// Merges the "city" values of each person into a list,
// one row per distinct "name" and "age"
df.implode("city")| name | age | city |
|---|---|---|
| Alice | 15 | [London, Milan] |
| Bob | 45 | [Tokyo, null] |
// Same as above, but `null` cities are removed from the lists
df.implode("city", dropNA = true)| name | age | city |
|---|---|---|
| Alice | 15 | [London, Milan] |
| Bob | 45 | [Tokyo] |
Return
A new DataFrame with one row per distinct combination of values in the other columns, where the specified columns contain merged lists of values.
Parameters
The column names used to select columns to implode.
If true, values (NAnull, Double.NaN or Float.NaN) are removed from the merged lists. false by default. Has no effect on imploded column groups and frame columns. Values are removed from each imploded column independently, so when several columns are imploded at once, their lists may stop lining up by position, and explode will not restore the original rows.
Type Parameters
The schema marker type of this DataFrame.
Deprecated
It's recommended to migrate to the String or Extension Properties Access API https://kotlin.github.io/dataframe/apilevels.html