I have a row from a data frame and I want to convert it to a Map[String, Any] that maps column names to the values in the row for that column.
Is there an easy way to do
You can convert your dataframe to rdd and use simple map function and use headernames in the MAP formation inside map function and finally use collect
dataframe
rdd
map
headernames
MAP
collect
val fn = df.schema.fieldNames val maps = df.rdd.map(row => fn.map(field => field -> row.getAs(field)).toMap).collect()