mapToRows

Returns a DataFrame with the rows 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 row, so the result can have fewer rows than the number of key–group pairs. Apart from that, the result has one row per pair, in the same order.

The columns of the result are the columns of the returned rows. If body returns null for every pair, the result has no rows and no columns at all, even though its type still says DataFrame<G> — so a result with no rows can carry no schema.

See also:

  • The Map Operation — an overview of the whole map family.

  • map — the same, but every result is kept, of any type, in a List.

  • concat — all rows of all groups, without computing anything.

Example

// The oldest person of every city, one row per city
df.groupBy { city }.mapToRows { group.sortByDesc { age }.firstOrNull() }

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

Return

A DataFrame with one computed row per key–group pair, without the null results.

Parameters

body

A Selector that computes a row of the result from a key–group pair, or null for no row.