从pypark dataframe将csv文件保存到s3存储桶中 [英] save a csv file into s3 bucket from pypark dataframe

查看:90
本文介绍了从pypark dataframe将csv文件保存到s3存储桶中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将spark数据帧的内容保存到s3存储桶中的csv文件中:

I would like to save the content of a spark dataframe into a csv file in s3 bucket:

df_country.repartition(1).write.csv('s3n://bucket/test/csv/a',sep=",",header=True,mode='overwrite')

创建名称为part-00000-fc644e84-7579-48的文件的问题.

the problem that it creaate a file with a name : part-00000-fc644e84-7579-48.

有什么办法可以修复此文件的名称.例如test.csv?

Is there any way to fix the name of this file. For example test.csv?

谢谢

最佳

推荐答案

这是不可能的,因为作业中的每个分区都会创建自己的文件,并且必须遵循严格的约定以避免命名冲突.推荐的解决方案是在创建文件后重命名该文件.

This is not possible since every partition in the job will create its own file and must follow a strict convention to avoid naming conflicts. The recommended solution is to rename the file after it is created.

此外,如果您知道每个路径只写入一个文件.前任. s3n://bucket/test/csv/a .那么文件的名称实际上并不重要,只需读取该唯一目录名称的所有内容即可.

Also, if you know you are only writing one file per path. Ex. s3n://bucket/test/csv/a. Then it doesn't really matter what the name of the file is, simply read in all the contents of that unique directory name.

来源:1. 在将DataFrame保存为CSV时指定文件名2. Spark数据帧保存在hdfs上的单个文件中位置

这篇关于从pypark dataframe将csv文件保存到s3存储桶中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆