convert
Converts the values in the specified columns either to a supported target type or using a custom converter, keeping their original names and positions within the DataFrame.
This function does not immediately convert the columns but instead selects columns to convert and returns a Convert, which serves as an intermediate step. The Convert object provides methods to transform selected columns using:
Additionally, it offers a wide range of methods for converting to specific types, such as toStr, toDouble, and many others.
For the full list of supported types, see SupportedTypes.
Each method returns a new DataFrame with the updated columns.
Check out Grammar.
This can include column groups and nested columns.
See Selecting Columns.
For more information: See convert on the documentation website.
See also parse — a specialized form of the convert operation that parses String columns into other types without requiring explicit type specification.
This Convert 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:
df.convert { columnA and columnB }.with { it.toString().lowercase() }
df.convert { colsOf<String>() }.to<Double>()
df.convert { colsAtAnyDepth().colGroups() }.asFrame { it.add("nan") { Double.NaN } }Parameters
The Columns Selector used to select the columns of this DataFrame to convert.
Converts the values in the specified columns either to a supported target type or using a custom converter, keeping their original names and positions within the DataFrame.
This function does not immediately convert the columns but instead selects columns to convert and returns a Convert, which serves as an intermediate step. The Convert object provides methods to transform selected columns using:
Additionally, it offers a wide range of methods for converting to specific types, such as toStr, toDouble, and many others.
For the full list of supported types, see SupportedTypes.
Each method returns a new DataFrame with the updated columns.
Check out Grammar.
This can include column groups and nested columns.
See Selecting Columns.
For more information: See convert on the documentation website.
See also parse — a specialized form of the convert operation that parses String columns into other types without requiring explicit type specification.
This Convert Overload
Select single or multiple columns using their names as Strings. (String API).
Example:
df.convert("person", "position").toStr()
df.convert("value").with { (it as Number).toDouble() }Parameters
The Column Names used to select the columns of this DataFrame to convert.
Converts specified columns using row converter expression within the DataFrame. Provide a new value for every selected cell given its row and its previous value using a row value expression.
For more information, See RowValueExpression on the documentation website. See convert on the documentation website.
Note
update with-, convert with- and add-like expressions use AddDataRow instead of DataRow as the DSL's receiver type. This is an extension to RowValueExpression and RowExpression that provides access to the modified/generated value of the preceding row (AddDataRow.newValue).
See Also
Convert per row colto provide a new value for every selected cell giving its column.
Example:
// Convert values in selected column to a trimmed `String`.
df.convert("valueA", "valueB") { it.toString().trim() }Return
A new DataFrame with the converted values.
Parameters
The Row Value Expression to update the rows with.
Defines how to convert values of the given type C.
For more information: See convertTo on the documentation website.
Deprecated
It's recommended to migrate to the String or Extension Properties Access API https://kotlin.github.io/dataframe/apilevels.html