rename

fun <T> DataFrame<T>.rename(vararg mappings: Pair<String, String>): DataFrame<T>

Renames columns in the DataFrame.

This function allows renaming multiple columns in a single call by supplying a list of name pairs. Each pair consists of the current column name and the desired new name.

See also renameToCamelCase which renames all columns to "camelCase" format.

Example:

df.rename("oldName1" to "newName1", "oldName2" to "newName2")

For more information: See rename on the documentation website.

Return

A new DataFrame with the renamed columns.

Parameters

mappings

A vararg of pairs where each pair consists of the original column name (first) and the new column name (second).


fun <T, C> DataFrame<T>.rename(columns: ColumnsSelector<T, C>): RenameClause<T, C>

Renames the specified columns keeping their original values and location within the DataFrame.

This function does not immediately rename the columns but instead selects columns to rename and returns a RenameClause, which serves as an intermediate step. The RenameClause object provides methods to rename selected columns using:

  • to(name) - renames selected columns to the specified names.

  • to { nameExpression } - renames selected columns using a provided expression assuming column with its path and returning a new name.

  • toCamelCase() - renames all selected columns to "camelCase".

Each method returns a new DataFrame with the renamed columns.

Check out Grammar.

This can include column groups and nested columns.

See Selecting Columns.

For more information: See rename on the documentation website.

See also renameToCamelCase which renames all columns to "camelCase" format.

This Rename 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:

// Rename "col1" to "width" and "col2" to "length"
df.rename { col1 and col2 }.to("width", "length")

// Rename all columns using their full path, delimited by "->"
df.rename { colsAtAnyDepth() }.to { it.path.joinToString("->") }

// Renames all numeric columns to "camelCase"
df.rename { colsOf<Number>() }.toCamelCase()

Parameters

columns

The Columns Selector used to select the columns of this DataFrame to rename.


fun <T> DataFrame<T>.rename(vararg cols: String): RenameClause<T, Any?>

Renames the specified columns keeping their original values and location within the DataFrame.

This function does not immediately rename the columns but instead selects columns to rename and returns a RenameClause, which serves as an intermediate step. The RenameClause object provides methods to rename selected columns using:

  • to(name) - renames selected columns to the specified names.

  • to { nameExpression } - renames selected columns using a provided expression assuming column with its path and returning a new name.

  • toCamelCase() - renames all selected columns to "camelCase".

Each method returns a new DataFrame with the renamed columns.

Check out Grammar.

This can include column groups and nested columns.

See Selecting Columns.

For more information: See rename on the documentation website.

See also renameToCamelCase which renames all columns to "camelCase" format.

This Rename Overload

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

Examples:

// Rename "col1" to "width" and "col2" to "length"
df.rename("col1", "col2").to("width", "length")

// Renames "arrival_date" and "passport-ID" columns to "camelCase"
df.rename("arrival_date", "passport-ID").toCamelCase()

Parameters

cols

The Column Names used to select the columns of this DataFrame to rename.


fun <T, C> DataFrame<T>.rename(vararg cols: ColumnReference<C>): RenameClause<T, C>
fun <T, C> DataFrame<T>.rename(vararg cols: KProperty<C>): RenameClause<T, C>
fun <T, C : ColumnReference<T>> C.rename(column: KProperty<T>): C
fun <T, C : ColumnReference<T>> C.rename(column: ColumnAccessor<T>): C

Deprecated

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