我有一个像
这样的数据框df.show
+----+-------+
| age| name|
+----+-------+
| 20|Michael|
| 30| Andy|
| 19| Justin|
+----+-------+
我需要将它放在像(Michael->20,Andy->30,Justin->19)
我怎样才能做到这一点?
答案 0 :(得分:1)
简单明了 - 转换为静态类型并收集:
df.select($"name", $"age".cast("int")).as[(String, Int)].collect.toMap
虽然在实践中我觉得它没有多大用处,因为它将数据存储在驱动程序内存中。