associate
The associate function builds a Map from key–value 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 Kotlin’s standard kotlin.collections.associate function.
The keys are in the same order as the rows. A key that occurs in several rows appears at the position of its first row, with the value of its last one.
Related functions
toMap— converts aDataFrameinto aMapby using column names as keys and their values as map values.associateBy— creates a map with rows as values.
Example
Create a map from name to age using a pair selector:
Output:
Both rules are visible at once if the city is taken as the key: London comes first, because the first person from London is in the first row, but it holds the last one. A row without a city gives a null key:
Output: