简体   繁体   中英

pyspark writing csv file to S3 error

I am using pyspark and I am having trouble writing to S3, but reading from S3 is not a problem.

this is my code:

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")

this is the error:

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

what is the problem?

See my comment above, you need to use a Spark DataFrame. One easy way to accomplish this would be to turn the index on the Pandas DF into a column and then convert to spark DF:

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

Then use:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM