map
Returns a new DataColumn with the values that transform computes from the values of this column.
transform is called once for every value of this column, from the first one to the last one, so the new column has as many values as this one, in the same order. The new column has the same name as this one.
Which kind of column you get follows the reified type argument R, and not the computed values: a DataFrame type gives a FrameColumn, a DataRow type gives a ColumnGroup, and any other type gives a ValueColumn. A nullable DataFrame type belongs to the last group, because a FrameColumn cannot hold null.
infer only concerns a ValueColumn: it decides whether the type of that column is the reified type argument R as it is, or the type of the computed values. For a ColumnGroup and a FrameColumn, infer changes nothing.
The computed values have to fit the reified type argument R. A ValueColumn can never have a non-nullable DataFrame type, so a call that would give it one fails with an IllegalArgumentException. That happens when the computed values are dataframes and Infer.Type derives a DataFrame type for them, and also under a nullable DataFrame type when none of the computed values is null: the default Infer.Nulls then drops the nullability and leaves exactly that forbidden type. With at least one null among them the same call succeeds and gives a ValueColumn of the nullable DataFrame type.
See also:
The Map Operation— an overview of the wholemapfamily.mapIndexed— the same, and the position of every value is given as well.the overload with an explicit
typeargument — when the type of the new column is only known at runtime.convert— computes new values for the selected columns of aDataFrameand replaces the old ones, instead of returning a single new column.
Example
// The lengths of the last names. The new column has the name of the original one,
// so it is usually renamed on the spot.
df.name.lastName.map { it.length }.rename("lastNameLength")For more information: See map on a DataColumn on the documentation website.
Return
A new DataColumn with the computed values.
Parameters
org.jetbrains.kotlinx.dataframe.api.Infer.Infer that indicates how DataColumn.type should be calculated. Either None, Nulls, or Type. By default: Nulls.
A function that computes a value of the new column from a value of this column.
Returns a new DataColumn of the given type with the values that transform computes from the values of this column.
transform is called once for every value of this column, from the first one to the last one, so the new column has as many values as this one, in the same order. The new column has the same name as this one.
Which kind of column you get follows the type argument, and not the computed values: a DataFrame type gives a FrameColumn, a DataRow type gives a ColumnGroup, and any other type gives a ValueColumn. A nullable DataFrame type belongs to the last group, because a FrameColumn cannot hold null.
infer only concerns a ValueColumn: it decides whether the type of that column is the type argument as it is, or the type of the computed values. For a ColumnGroup and a FrameColumn, infer changes nothing.
The computed values have to fit the type argument. A ValueColumn can never have a non-nullable DataFrame type, so a call that would give it one fails with an IllegalArgumentException. That happens when the computed values are dataframes and Infer.Type derives a DataFrame type for them, and also under a nullable DataFrame type when none of the computed values is null: the default Infer.Nulls then drops the nullability and leaves exactly that forbidden type. With at least one null among them the same call succeeds and gives a ValueColumn of the nullable DataFrame type.
See also:
The Map Operation— an overview of the wholemapfamily.mapIndexed— the same, and the position of every value is given as well.the overload without a
typeargument — when the type of the new column is known at compile time.
Example
// A column of ages typed `Number` on purpose, even though every value is an `Int`
df.age.map(typeOf<Number>()) { it }For more information: See map on a DataColumn on the documentation website.
Return
A new DataColumn with the computed values.
Parameters
The type to give to the new column. The computed values are put into the column as they are, without any conversion, so type has to fit them. With Infer.Type the type of a ValueColumn comes from the computed values instead, and type is only used when the column is empty and there are no values to take it from. Note that type and the type argument R are independent: the result is a DataColumn<R> for the compiler, while its type at runtime is type. Keep the two in agreement unless that difference is exactly what you are after.
org.jetbrains.kotlinx.dataframe.api.Infer.Infer that indicates how DataColumn.type should be calculated. Either None, Nulls, or Type. By default: Nulls.
A function that computes a value of the new column from a value of this column.
Returns a List with the values that transform computes from the rows of this DataFrame.
transform is called once for every row, from the first one to the last one, so the list has one element per row, in row order.
transform gets the row both as its receiver and as its argument, so inside it age and it.age mean the same thing. For more information: See Row Expressions on the documentation website.
The result is an ordinary List, and not a DataFrame or a DataColumn.
A ColumnGroup is also a DataFrame, so map on a column group is this function, and its result is a List with one element per row of the group. To get a DataColumn of the same size instead — a column of the DataRows of the group — call asDataColumn first, and then map.
See also:
The Map Operation— an overview of the wholemapfamily.mapToColumn— the same, but the results are collected into aDataColumn.mapToFrame— a newDataFrameof several computed columns at once.rows— the rows themselves, when nothing has to be computed.
Example
// The list of birth years, one per row
df.map { 2021 - age }For more information: See map over rows on the documentation website.
Return
Parameters
A RowExpression that computes an element of the list from a row of this DataFrame.
Returns a List with the values that body computes from the key–group pairs of this GroupBy.
body is called once for every key–group pair of this GroupBy, in the order in which the pairs appear in it. Each pair is given to body as a GroupWithKey, both as the receiver and as the argument, so the key values are available as key and the rows of the group as group.
A pair for which body returns null gives no element, so the list can be shorter than the number of key–group pairs. Apart from that, the list has one element per pair, in the same order.
See also:
The Map Operation— an overview of the wholemapfamily.mapToRows— the same, but every result is a row, collected into aDataFrame.mapToFrames— the same, but every result is aDataFrame, collected into aFrameColumn.aggregate— computes named values per group and returns them as aDataFramenext to the key columns.
Example
// The number of people per city, as a list, in the order of the groups: [1, 1, 2, 1, 1, 1]
df.groupBy { city }.map { group.rowsCount() }For more information: See map on a GroupBy on the documentation website.
Return
A List with one computed element per key–group pair, without the null results.
Parameters
A Selector that computes an element of the list from a key–group pair.
Deprecated
It's recommended to migrate to the String or Extension Properties Access API https://kotlin.github.io/dataframe/apilevels.html