我有这个代码,我写的是本地文件系统上的csv文件,但是我收到了错误 - IOError: [Errno 2] No such file or directory: 'file:///folder1/folder2/output.csv'
columns = [0,1,2,3,4,5,6,7,8,9]
data1 = rdd1.map(lambda row: [row[i].encode("utf-8") for i in columns])
data1_tuple = data1.map(tuple)
with open("file:///folder1/folder2/output.csv", "w") as fw:
writer = csv.writer(fw, delimiter = ';')
for (r1, r2) in izip(data1_tuple.toLocalIterator(), labelsAndPredictions.toLocalIterator()):
writer.writerow(r1 + r2[1:2])
在我的本地文件系统上,存在以下目录 - /folder1/folder2/
。为什么会抛出此错误,如何在特定目录的本地filesytem上写入csv文件?
答案 0 :(得分:1)
path
参数是
字符串或字节对象,给出要打开的文件的路径名(绝对或相对于当前工作目录)或要包装的文件的整数文件描述符
不是URI。这意味着您的代码应如下所示:
with open("/folder1/folder2/output.csv", "w") as fw:
writer = csv.writer(fw, delimiter = ';')
...