forEach

inline fun <T> DataColumn<T>.forEach(action: (T) -> Unit)

Calls action for every value of this DataColumn, from the first one to the last one.

This function returns Unit, so it is only useful for its side effects, such as printing values or collecting them. To get a new DataColumn of computed values instead, use map.

For more information: See forEach on a DataColumn on the documentation website.

See also forEachIndexed — the same, and the position of every value is given as well.

Example

// Prints the ages, from the first value to the last one:
// 15, 45, 20, 40, 30, 20, 30
df.age.forEach { println(it) }

Parameters

action

A function that is called with every value of this column.


inline fun <T> DataFrame<T>.forEach(action: RowExpression<T, Unit>)

Calls action for every row of this DataFrame, from the first one to the last one.

action gets the row both as its receiver and as its argument, so inside it age and it.age mean the same thing.

This function returns Unit, so it is only useful for its side effects, such as printing values or collecting them. To get a List of computed values instead, use map.

For more information: See iterating on the documentation website. See Row Expressions on the documentation website.

See also:

Example

// Prints the age of every person, from the first row to the last one
df.forEach { println(it.age) }

Parameters

action

A RowExpression that is called with every row of this DataFrame.


inline fun <T, G> GroupBy<T, G>.forEach(body: (GroupBy.Entry<T, G>) -> Unit)

Calls body for every key–group pair of this GroupBy, in the order in which the pairs appear in it.

body gets each pair as a GroupBy.Entry: its key is the row of keys with the key values, and its group is a DataFrame with the rows of that group. The entry can be destructured, as (key, group).

This function returns Unit, so it is only useful for its side effects, such as printing values or collecting them. To get a List of computed values instead, use map.

For more information: See forEach on a GroupBy on the documentation website.

See also forEach — goes over the rows of a DataFrame.

Example

// Prints the number of people per city:
// "London: 1", "Dubai: 1", "Moscow: 2", ...
df.groupBy { city }.forEach { (key, group) ->
println("${key.city}: ${group.rowsCount()}")
}

Parameters

body

A function that is called with every key–group pair of this GroupBy.