Files
2026-02-08 11:20:43 -10:00

1.6 KiB
Vendored
Raw Permalink Blame History

associate

Discover `associate` operation for Kotlin DataFrame. Discover `associate` operation for Kotlin DataFrame. Discover `associate` operation for Kotlin DataFrame.

The associate function builds a Map from keyvalue Pairs produced by applying a transformation to each row of this DataFrame using a row expression.

If multiple rows produce the same key, only the last value for that key is kept. This matches the behavior of Kotlins standard kotlin.collections.associate function.

df.associate { pairSelector }

pairSelector: (DataRow) -> Pair
  • toMap — converts a DataFrame into a Map by using column names as keys and their values as map values.
  • associateBy — creates a map with rows as values.

Example

df

Create a map from name to age using a pair selector:

df.associate { "${name.firstName} ${name.lastName}" to age }

Output:

{
  Alice Cooper: 15,
  Bob Dylan: 45,
  Charlie Daniels: 20,
  Charlie Chaplin: 40,
  Bob Marley: 30,
  Alice Wolf: 20,
  Charlie Byrd: 30
}