pyspark将csv文件写入S3错误

时间:2018-01-04 09:50:37

标签: python amazon-s3

我正在使用pyspark而我在写入S3时遇到了问题,但从S3读取不是问题。

这是我的代码:

dic = {'a': {'c1(%)': 0.0, 'c2': 0, 'c3($)': 260, 'c4(%)': 4.79, 'c5': 78, 'c6': 352}, 'b': {'c1(%)': 0.0, 'c2': 0, 'c3($)': 5, 'c4(%)': 0.09, 'c5': 2, 'c6': 280}, 'c': {'c1(%)': 0.0, 'c2': 0, 'c3($)': 0, 'c4(%)': 0.0, 'c5': 0, 'c6': 267}}

df = pd.DataFrame(dic)

df.to_csv("s3://work/.../filename_2018-01-04_08:50:45.csv")

这是错误:

IOError: [Errno 2] No such file or directory: 's3://work/.../filename_2018-01-04_08:50:45.csv'

问题是什么?

1 个答案:

答案 0 :(得分:2)

请参阅上面的评论,您需要使用Spark DataFrame。实现此目的的一种简单方法是将Pandas DF上的索引转换为列,然后转换为spark DF:

df2=sqlContext.createDataFrame(df.reset_index(drop=False))

然后使用:

df2.write.save("s3://work/.../filename_2018-01-04_08:50:45.csv", format='csv', header=True)
相关问题