0

我想将 spark 数据帧作为单个分区 csv 写入 stringIO。然后应该使用 ftp 将这个单独分区的 csv 发送到另一台服务器。

以下行似乎不起作用:

df.repartition(1).write.csv(file_buffer,mode="overwrite", header=True)

输出是以下错误:

py4j.protocol.Py4JError: An error occurred while calling o148.csv. Trace:
py4j.Py4JException: Method csv([class java.util.ArrayList]) does not exist

from ftplib import FTP
import StringIO

file_buffer = StringIO.StringIO()
df.repartition(1).write.csv(file_buffer,mode="overwrite", header=True)

ftp = FTP()
ftp.connect(host, 21)
ftp.login(user=user, passwd=pw)
ftp.storbinary('test.csv', file_buffer)
ftp.quit()

我也试过了df.coalesce(1).write.csv(file_buffer,mode="overwrite", header=True)。但是,这会返回相同的错误。顺便说一句,我主要可以使用上述方法写入 S3。提前谢谢了!

4

0 回答 0