asColumn

inline fun <T, C, R> Convert<T, C>.asColumn(crossinline columnConverter: DataFrame<T>.(DataColumn<C>) -> BaseColumn<R>): DataFrame<T>

Converts values in the columns previously selected with convert using columnConverter expression within the DataFrame.

The columnConverter is a lambda with the current DataFrame as receiver and the selected column as argument. It returns a new column that will replace the original column. Preserves original column name for each column (even it was explicitly changed in columnConverter expression).

For more information: See convert on the documentation website.

It's a compiler plugin-friendly variant of ReplaceClause.with. ReplaceClause.with allows you to change both column types and names. Tracking of column name changes in arbitrary lambda expression is unreliable and generally impossible to do statically. This function ensures that all column names remain as is and only their type changes to R

See Also

  • Convert with to provide a new value for every selected cell giving its row and its previous value.

  • Replace with to replace columns using a column converter, allowing both column names and types to be changed.

Examples:

// Convert all columns into column groups, each containing the original column
df.convert { all() }.asColumn { listOf(it).toColumnGroup(it.name) }
// Converts all `String` columns by applying heavyIO to each element in parallel and assembling results back into columns.
df.convert { colsOf<String>() }.asColumn { it.asList().parallelStream().map { heavyIO(it) }.toList().toColumn() }`

Return

A new DataFrame with the values converted to type.