Dataframe 0.12 Help

convert

Returns DataFrame with changed values in some columns. Allows changing column types.

convert { columnsSelector } .with { rowExpression } | .perRowCol { rowColExpression } | to<Type>() | to { colExpression } rowExpression = DataRow.(OldValue) -> NewValue rowColExpression = (DataRow, DataColumn) -> NewValue colExpression = DataFrame.(DataColumn) -> DataColumn

See column selectors and row expressions

df.convert { age }.with { it.toDouble() } df.convert { colsOf<String>().recursively() }.with { it.toCharArray().toList() }

convert supports automatic type conversions between the following types:

  • Int

  • String

  • Double

  • Long

  • Short

  • Float

  • BigDecimal

  • LocalDateTime

  • LocalDate

  • LocalTime

  • Duration

df.convert { age }.to<Double>() df.convert { colsOf<Number>() }.to<String>() df.convert { name.firstName and name.lastName }.to { it.length() } df.convert { weight }.toFloat()

Automatic conversion from String to enum classes is also supported:

enum class Direction { NORTH, SOUTH, WEST, EAST }
dataFrameOf("direction")("NORTH", "WEST") .convert("direction").to<Direction>()
Last modified: 01 December 2023