Create DataColumn
This section describes ways to create a DataColumn
.
columnOf
Returns new column with the given elements. The column type
is deduced from the compile-time type of the elements inside. The column name
is taken from the name of the variable.
// Create ValueColumn with name 'student' and two elements of type String
val student by columnOf("Alice", "Bob")
To assign column name explicitly, use the named
infix function and replace by
with =
.
val column = columnOf("Alice", "Bob") named "student"
When column elements are columns themselves, it returns a ColumnGroup
:
val firstName by columnOf("Alice", "Bob")
val lastName by columnOf("Cooper", "Marley")
// Create ColumnGroup with two nested columns
val fullName by columnOf(firstName, lastName)
When column elements are DataFrame
objects it returns a FrameColumn
:
val df1 = dataFrameOf("name", "age")("Alice", 20, "Bob", 25)
val df2 = dataFrameOf("name", "temp")("Charlie", 36.6)
// Create FrameColumn with two elements of type DataFrame
val frames by columnOf(df1, df2)
toColumn
Converts an Iterable
of values into a column.
listOf("Alice", "Bob").toColumn("name")
To compute a column type at runtime by scanning through the actual values, enable the Infer.Type
option.
To inspect values only for nullability, enable the Infer.Nulls
option.
val values: List<Any?> = listOf(1, 2.5)
values.toColumn("data") // type: Any?
values.toColumn("data", Infer.Type) // type: Number
values.toColumn("data", Infer.Nulls) // type: Any
toColumnOf
Converts an Iterable
of values into a column of a given type:
val values: List<Any?> = listOf(1, 2.5)
values.toColumnOf<Number?>("data") // type: Number?
Last modified: 09 December 2024