Python Pyspark脚本在整个数据集上失败,但在单个文件上起作用

时间:2019-10-31 09:24:57

标签: python apache-spark pyspark

enter image description here我编写了一个python pyspark脚本,该脚本从data中提取特定功能。该脚本可以在单个file.json上正常运行,并返回一个包含我所有功能的数据框作为输出。我的问题是我需要一次在整个数据集(包含json文件的文件夹)上运行脚本。谁能建议一个好方法吗?谢谢<code>my output features_dataframe</code>

代码示例:

sc.map(mapper).reduce(reducer)

1 个答案:

答案 0 :(得分:1)

您可以按以下方式使用:

finalDF = spark.read.json('/path/to/json/directory/*.json')