我有以下结构的数据框:
root
|-- index: long (nullable = true)
|-- text: string (nullable = true)
|-- topicDistribution: struct (nullable = true)
| |-- type: long (nullable = true)
| |-- values: array (nullable = true)
| | |-- element: double (containsNull = true)
|-- wiki_index: string (nullable = true)
我需要将其更改为:
root
|-- index: long (nullable = true)
|-- text: string (nullable = true)
|-- topicDistribution: array (nullable = true)
| |-- element: double (containsNull = true)
|-- wiki_index: string (nullable = true)
请问我怎么能这样做?
非常感谢。
答案 0 :(得分:4)
我认为你正在寻找
df.withColumn("topicDistribution", col("topicDistribution").getField("values"))