into
Reshapes the columns previously selected by gather into two new columns: keyColumn, containing the original column names, and valueColumn, containing the corresponding cell values.
Returns a new DataFrame with the reshaped structure. The original gathered columns are removed from the result, while all other columns remain unchanged — except that their values are duplicated for each generated key-value pair.
Key and value values can be adjusted beforehand using mapKeys and mapValues, respectively.
For more information, see: See gather on the documentation website.
See also: Grammar.
Example
// Gather `resultA` and `resultB` columns into a single "value" column,
// with the "series" column containing a key derived from the last letter
// of the original column names (i.e., 'A' or 'B').
df.gather { resultA and resultB }
.mapKeys { it.last() }
.into("series", "value")Return
A new DataFrame with reshaped columns.
Parameters
The name of the column to store keys (original column names by default).
The name of the column to store gathered values.
Groups columns, previously selected with group, into new or existing column groups within the DataFrame, using a ColumnsSelectionDsl expression to specify the target group name for each column. The expression is applied to each selected column and determines the name of the column group it will be placed into.
If a column group with the specified name does not exist, it will be created.
See Selecting Columns.
For more information: See group on the documentation website.
Select single or multiple columns using their names as Strings. (String API).
Example:
// For each selected column, place it under its under a group with its type as name (individual for each column):
df.group { all() }.into { it.type().toString() }Parameters
A ColumnsSelector expression that takes a column and returns the name of the ColumnGroup where that column should be grouped. All selected columns will be moved under the groups defined by this expression.
Groups columns, previously selected with group, into a new or existing column group within the DataFrame by specifying its path via ColumnsSelectionDsl expression.
If the specified path is partially or fully missing — that is, if any segment of the path does not correspond to an existing column or column group — all missing parts will be created automatically.
See Selecting Columns.
For more information: See group on the documentation website.
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:
// Group selected columns into an existing column group (common for all selected columns):
df.group("age", "weight").into { info }
// Group selected columns into a nested column group using a path (common for all selected columns) that may contain both existing and new segments:
df.group { employee.age and employee.weight }.into { pathOf("info", "personal") }
// For each selected column, place it under its ancestor group from two levels up in the column path hierarchy (individual for each column):
df.group { colsAtAnyDepth().colsOf<String>() }.into { it.path.dropLast(2) }Parameters
A ColumnsSelector expression that takes a column and returns the full path to the ColumnGroup where that column should be grouped. All selected columns will be moved under the groups defined by this expression.
Groups columns, previously selected with group, into a new or existing column group within the DataFrame, by specifying its name.
If a column group with the specified name does not exist, it will be created.
See Selecting Columns.
For more information: See group on the documentation website.
Select single or multiple columns using their names as Strings. (String API).
Examples:
df.group("age", "weight").into("info")
df.group { age and weight }.into("info")Parameters
A ColumnsSelector that defines the path to a ColumnGroup in the DataFrame, where the selected columns will be moved.
Converts this GroupBy into a DataFrame.
Does the same as GroupBy.toDataFrame.
Each row of the resulting DataFrame represents a unique keys–group pair: a row from keys and its corresponding group of rows (as DataFrame).
Resulting DataFrame contains a FrameColumn with groups.
Check out groupBy Grammar.
For more information: See groupBy on the documentation website.
Return
A new DataFrame that includes the grouping key columns together with a FrameColumn containing the corresponding groups.
Parameters
The name of the column in which to store grouped data.
Aggregates this GroupBy into a DataFrame by computing the values of expression on all rows for each group.
Each row of the resulting DataFrame represents a unique keys–value pair: a row from keys and list of values, computed on all rows of the corresponding group using provided expression.
Check out groupBy Grammar.
See Row Expression
For more information: See groupBy on the documentation website.
Example
// Compute list of prices within each city
// by multiplying "amount" and "cost" values.
df.groupBy { city }.into("prices") {
amount * cost
}Return
A new DataFrame that includes the grouping key columns together with a list of values computed on all rows of corresponding groups.
Parameters
The name of the column in which to store aggregated data.
The expression to compute on each group row.
Moves columns, previously selected with move into a new position specified by a given column path within the DataFrame.
If the specified path is partially or fully missing — that is, if any segment of the path does not correspond to an existing column or column group — all missing parts will be created automatically.
See Selecting Columns.
For more information: See move on the documentation website.
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:
df.move { age and weight }.into { pathOf("info", it.name()) }
df.move { age and weight }.into { "info"[it.name()] }
df.move { name.firstName and name.lastName }.into { pathOf("fullName", it.name().dropLast(4)) }Parameters
The Column With Path Selector used to specify a path in the DataFrame to move columns.
Moves the selected column, previously specified with move, to the top level of the DataFrame and assigns it a new name.
For more information: See move on the documentation website.
Example:
// Move "info"."salary" column to the top level with a new name "income"
df.move { info.salary }.into("income")Return
A new DataFrame with the column moved and renamed.
Parameters
The new String name of the column after the move.
Deprecated
It's recommended to migrate to the String or Extension Properties Access API https://kotlin.github.io/dataframe/apilevels.html
Deprecated
'into' has been replaced with 'to', because 'rename to' is more common in English. You can keep using 'into', but we advise using 'to'.
Replace with
to(*newNames)NOTE: While you can keep using 'into', we recommend using to for better readability and more natural English.
Renames the columns selected with rename to the specified newNames, preserving their values and positions within the DataFrame.
The mapping is positional: newNames are applied in the order the columns were selected — the first selected column is renamed to the first name, the second to the second, and so on.
For more information: See rename on the documentation website.
Check out Grammar.
Examples:
// Rename "col1" to "width" and "col2" to "length"
df.rename("col1", "col2").into("width", "length")
// Rename "col1" to "width" and "col2" to "length"
df.rename { col1 and col2 }.into("width", "length")Return
A new DataFrame with the columns renamed.
Parameters
The new names for the selected columns, applied in order of selecting.
Deprecated
'into' has been replaced with 'to', because 'rename to' is more common in English. You can keep using 'into', but we advise using 'to'.
Replace with
to(transform)NOTE: While you can keep using 'into', we recommend using to for better readability and more natural English.
Renames the columns selected with rename by applying the transform expression to each of them. This expression receives the column together with its full path (as ColumnWithPath) and must return the new name for that column. The operation preserves the original columns’ values and their positions within the DataFrame.
For more information: See rename on the documentation website.
Check out Grammar for more details.
Examples:
// Rename all columns using their full path, delimited by "->"
df.rename { colsAtAnyDepth() }.into { it.path.joinToString("->") }
// Rename all `String` columns with uppercase
df.rename { colsOf<String>() }.into { it.name.uppercase() }Return
A new DataFrame with the columns renamed.
Parameters
A function that takes a ColumnWithPath for each selected column and returns the new column name.
Deprecated
Please explicitly specify how the String should be split. Shortcut: Will be ERROR in 1.1.
Replace with
by(",").into(*names, extraNamesGenerator = extraNamesGenerator)