Reputation: 21
I have input data like given below in a pyspark dataframe,
and i want to convert it into the tabular form like below,
Please help me out as i am pretty new to pyspark.
Upvotes: 0
Views: 37
Reputation: 10372
You can use from_json
along with 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 |
+-------+------+-------+
Upvotes: 0