我想将带有列的表转换为databricks pyspark上的字符串数组。
我的桌子:
id values (array<string>)
rgf ['vwervfrev', 'fweccf', 'tuyhert']
rty ['evvverws', 'ilonmunt', 'cedcrhb']
我需要什么:
id values
rdf 'vwervfrev'
rdf 'fweccf'
rdf 'tuyhert'
rty 'evvverws'
rty 'ilonmunt'
rty 'cedcrhb'
我不确定如何进行转换?
谢谢
答案 0 :(得分:1)
您可以使用爆炸功能来做到这一点:
from pyspark.sql.functions import explode, col
new_df = df.withColumn("values", explode(col("values")))
new_df.show()
https://spark.apache.org/docs/latest/api/python/_modules/pyspark/sql/functions.html#explode