mapIndexed
Returns a new DataColumn with the values that transform computes from the values of this column and their positions.
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.
The position of the first value is 0.
See also:
The Map Operation— an overview of the wholemapfamily.map— the same, without the positions.the overload with an explicit
typeargument — when the type of the new column is only known at runtime.
Example
// The first names, numbered: "1. Alice", "2. Bob", ...
df.name.firstName.mapIndexed { i, firstName -> "${i + 1}. $firstName" }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 the position of a value of this column and that value.
Returns a new DataColumn of the given type with the values that transform computes from the values of this column and their positions.
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.
The position of the first value is 0.
See also:
The Map Operation— an overview of the wholemapfamily.map— the same, without the positions.the overload without a
typeargument — when the type of the new column is known at compile time.
Example
// The positions of the rows, in a column typed `Number` on purpose
df.age.mapIndexed(typeOf<Number>()) { i, _ -> i }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 the position of a value of this column and that value.