map
Creates List
, DataFrame or DataColumn with values computed from rows of original DataFrame.
Map into List
:
map { rowExpression }: List<T>
rowExpression: DataRow.(DataRow) -> Value
df.map { 2021 - it.age }
Map into DataColumn
:
mapToColumn(columnName) { rowExpression }: DataColumn
rowExpression: DataRow.(DataRow) -> Value
df.mapToColumn("year of birth") { 2021 - age }
val age by column<Int>()
val yearOfBirth by column<Int>("year of birth")
df.mapToColumn(yearOfBirth) { 2021 - age }
df.mapToColumn("year of birth") { 2021 - "age"<Int>() }
See row expressions
Map into DataFrame
:
mapToFrame {
columnMapping
columnMapping
...
} : DataFrame
columnMapping = column into columnName | columnName from column | columnName from { rowExpression } | +column
df.mapToFrame {
"year of birth" from 2021 - age
age gt 18 into "is adult"
name.lastName.length() into "last name length"
"full name" from { name.firstName + " " + name.lastName }
+city
}
val yob = column<Int>("year of birth")
val lastNameLength = column<Int>("last name length")
val age by column<Int>()
val isAdult = column<Boolean>("is adult")
val fullName = column<String>("full name")
val name by columnGroup()
val firstName by name.column<String>()
val lastName by name.column<String>()
val city by column<String?>()
df.mapToFrame {
yob from 2021 - age
age gt 18 into isAdult
lastName.length() into lastNameLength
fullName from { firstName() + " " + lastName() }
+city
}
df.mapToFrame {
"year of birth" from 2021 - "age"<Int>()
"age"<Int>() gt 18 into "is adult"
"name"["lastName"]<String>().length() into "last name length"
"full name" from { "name"["firstName"]<String>() + " " + "name"["lastName"]<String>() }
+"city"
}
Last modified: 27 September 2024