How to convert json to pyspark dataframe (faster implementation) [duplicate]

99封情书 提交于 2020-01-07 03:47:06

问题


I have json data in form of {'abc':1, 'def':2, 'ghi':3} How to convert it into pyspark dataframe in python?


回答1:


import json
j = {'abc':1, 'def':2, 'ghi':3}
a=[json.dumps(j)]
jsonRDD = sc.parallelize(a)
df = spark.read.json(jsonRDD)

>>> df.show()
+---+---+---+
|abc|def|ghi|
+---+---+---+
|  1|  2|  3|
+---+---+---+


来源:https://stackoverflow.com/questions/44456076/how-to-convert-json-to-pyspark-dataframe-faster-implementation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!