如何从以不同列为条件的PySpark数据框中提取数组元素? [英] How to extract array element from PySpark dataframe conditioned on different column?
本文介绍了如何从以不同列为条件的PySpark数据框中提取数组元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下 PySpark输入数据框:
+-------+------------+
| index | valuelist |
+-------+------------+
| 1.0 | [10,20,30] |
| 2.0 | [11,21,31] |
| 0.0 | [14,12,15] |
+-------+------------+
位置:
- 索引:输入Double
- 值列表:输入 Vector . (它是 NOT阵列)
- Index: type Double
- Valuelist: type Vector. (it's NOT Array)
从上面的输入数据框中,我想在 PySpark
From the above Input Dataframe, I want to get the following Output Dataframe in PySpark
+-------+-------+
| index | value |
+-------+-------+
| 1.0 | 20 |
| 2.0 | 31 |
| 0.0 | 14 |
+-------+-------+
逻辑:
for each row:
value = valuelist[index]
推荐答案
Spark 1.5及更高版本
查看全文