我想将数组(Int,Int)列从dataframe中爆炸
投入:
colA newCol
1 [[1a, 2],[3c, 5u]]
2 [[1c, 9m], [5e, 7l]]产出:
colA newCol
1 1a
1 3c
2 1c
2 5e发布于 2019-08-01 05:07:15
这是我的方法。
+----+--------------------+
|col1|col2 |
+----+--------------------+
|1 |[[1a, 2b], [3c, 5u]]|
|2 |[[1c, 9m], [5e, 7l]]|
+----+--------------------+这是你的数据
df.withColumn("t", explode($"col2")).selectExpr("col1", "t[0]").show我的代码结果是
+----+----+
|col1|t[0]|
+----+----+
| 1| 1a|
| 1| 3c|
| 2| 1c|
| 2| 5e|
+----+----+https://stackoverflow.com/questions/57301798
复制相似问题