Skip to content

Instantly share code, notes, and snippets.

@1ambda
Created December 21, 2021 23:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 1ambda/422bbf3e06f353103cb23ba55f7ae109 to your computer and use it in GitHub Desktop.
Save 1ambda/422bbf3e06f353103cb23ba55f7ae109 to your computer and use it in GitHub Desktop.
structCategory = StructType(
[
StructField("category_id", LongType(), True),
StructField("category_code", StringType(), True),
]
)
dfStructed = dfCategory\
.withColumn("category_parsed", from_json(col("category"), structCategory))
dfStructed.printSchema()
dfStructed.show(truncate=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment