我尝试将spark df列转换成行,如下面的示例所示。
scala> df.show()
+----+--------------------+
|year| String|
+----+--------------------+
|ina|List(Apple, 136, Train ...)...|
|inb|List(Orange, 4.36, car ...)...|
|ina|List(Apple,34, plane ...)...|
+----+--------------------+
并创建一个输出df,如下所示:
+----+-------------+-------------+
|year|key|String|
+----+-------------+-------------+
|ina|Apple |136 |
|inb|Car |4.36 |
|ina|Orange |34 |
如何获得所需的输出?使用explode?
非常感谢!
1条答案
按热度按时间pgvzfuti1#
如果将值列视为json:
给予:
如果需要,请重命名列