首页 > 解决方案 > 在pyspark中用格式编写json

问题描述

我想在 pyspark 中将数据帧写为 json 数据帧,以复制这种方式从 pandas 写入 json:

df.to_json(orient='columns') 

然后我得到了

'{"col 1":{"row 1":"a","row 2":"c"},"col 2":{"row 1":"b","row 2":"d"}}'

但是当我在 AWS GLUE 中使用它时

df.write.mode('overwrite').json(path) 

我得到了这种格式:

df.to_json(orient='records')
'[{"col 1":"a","col 2":"b"},{"col 1":"c","col 2":"d"

我在 pyspark 中发现了 json 的参数,并且没有设置 json 格式的方向

标签: jsonpandaspysparkformataws-glue

解决方案


推荐阅读