mapToColumn
Returns a new DataColumn with the given name and the values that body computes from the rows of this DataFrame.
body is called once for every row, from the first one to the last one, so the new column has one value per row, in row order. The new column is standalone: this DataFrame is not changed and does not contain it.
With an AddExpression, you define the value that each row in the new column should have. This can be based on values from the same row in the original DataFrame.
You can also use functions like prev and next to access other rows, and combine them with newValue to reference values already computed in the new column. For example, use prev().newValue() to access the new column value from the previous row.
See also:
The Map Operation— an overview of the wholemapfamily.add— the same, but the result is thisDataFramewith the new column in it.expr— the same inside the Columns Selection DSL.
Example
// A standalone column of birth years; `df` itself is left as it was
val yearOfBirth = df.mapToColumn("year of birth") { 2021 - age }For more information: See mapToColumn on the documentation website.
Return
A new DataColumn with the computed values.
Parameters
The name to give to the new column.
org.jetbrains.kotlinx.dataframe.api.Infer.Infer that indicates how DataColumn.type should be calculated. Either None, Nulls, or Type. By default: Nulls.
An AddExpression that computes a value of the new column from a row of this DataFrame.
Deprecated
Deprecated duplicated functionality. Will be ERROR in 1.1.
Replace with
import org.jetbrains.kotlinx.dataframe.api.Infer
expr(name, infer, body)Returns a new DataColumn with the given name and the values that body computes from the rows of this ColumnsContainer.
Use expr instead — it does the same and works in every Columns Selection DSL.
Deprecated
It's recommended to migrate to the String or Extension Properties Access API https://kotlin.github.io/dataframe/apilevels.html