Pyspark - 将Json类型数据转换为表格形式

问题描述 投票:0回答:1

我在 pyspark 数据框中输入了如下所示的输入数据,

我想将其转换为如下所示的表格形式,

请帮助我,因为我对 pyspark 还很陌生。

json pyspark databricks
1个回答
0
投票

您可以将

from_json
schema

一起使用
df
.withColumn(
   "Results", 
   expr("from_json(Results, 'country string, gender string, city string')")
)
.selectExpr("Results.*")
.show(False)

+-------+------+-------+
|country|gender|city   |
+-------+------+-------+
|Germnay|male  |Hamburg|
|India  |male  |Delhi  |
|France |female|paris  |
|Germnay|male  |Munich |
+-------+------+-------+
© www.soinside.com 2019 - 2024. All rights reserved.