您可以将
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 |
+-------+------+-------+