我的建议是与RDD合作完成这项任务。
像这样写:
rdd = # collection of Rows with the following fields: userid, type, data - your CSV
def flatten_json(userid, type, data_json):
final_row = {"userid": userid, "type": type, "data_sids": data_json["sids"], ...}
return Row(**final_row)
rdd = rdd.map(lambda row: flatten_json(row["userid"], row["type"], row["data"]))
df = spark.createDataFrame(rdd)
就这样:)