0
我有以下模式的DF:如何將數組轉換爲串有效地在python/pyspark
root
|-- col1: string (nullable = true)
|-- col2: array (nullable = true)
| |-- element: string (containsNull = true)
在其中的一列,COL2是陣列[1個#B,2·B ,3#C]。我想將它轉換爲這種字符串格式1#b,2#b,3#c。
我目前做這通過下面的代碼片段
df2 = (df1.select("*",explode(col2)).drop('col2'))
df2.groupBy("col1").agg(concat_ws(",", collect_list('col')).alias("col2"))
雖然這能夠完成任務,它需要時間,也顯得效率低下。有更好的選擇嗎?