小编lum*_*umi的帖子

合并双类型列后从数组中删除空值

我有这个 PySpark df

+---------+----+----+----+----+----+----+----+----+----+                        
|partition|   1|   2|   3|   4|   5|   6|   7|   8|   9|
+---------+----+----+----+----+----+----+----+----+----+
|        7|null|null|null|null|null|null| 0.7|null|null|
|        1| 0.2| 0.1| 0.3|null|null|null|null|null|null|
|        8|null|null|null|null|null|null|null| 0.8|null|
|        4|null|null|null| 0.4| 0.5| 0.6|null|null| 0.9|
+---------+----+----+----+----+----+----+----+----+----+
Run Code Online (Sandbox Code Playgroud)

我将其中的 9 列组合起来:

+---------+--------------------+                                                
|partition|            vec_comb|
+---------+--------------------+
|        7|      [,,,,,,,, 0.7]|
|        1|[,,,,,, 0.1, 0.2,...|
|        8|      [,,,,,,,, 0.8]|
|        4|[,,,,, 0.4, 0.5, ...|
+---------+--------------------+
Run Code Online (Sandbox Code Playgroud)

如何NullTypes从列数组中删除vec_comb

预期输出:

+---------+--------------------+                                                
|partition|            vec_comb|
+---------+--------------------+
|        7|               [0.7]|
|        1|      [0.1, 0.2,0.3]|
|        8|               [0.8]|
| …
Run Code Online (Sandbox Code Playgroud)

python arrays null apache-spark pyspark

3
推荐指数
1
解决办法
3380
查看次数

标签 统计

apache-spark ×1

arrays ×1

null ×1

pyspark ×1

python ×1