[英]to_csv "No Such File or Directory" But the directory does exist - Databricks on ADLS
我已经看到这个问题的许多迭代,但似乎无法理解/修复这种行为。
我在 Azure Databricks 上使用 DBR 10.4 LTS Spark 3.2.1 Scala 2.12 尝试将单个 csv 文件写入 blob 存储,以便可以将其删除到 SFTP 服务器。 无法使用 spark-sftp,因为不幸的是我使用的是 Scala 2.12,无法使该库正常工作。
鉴于这是一个小数据框,我将其转换为 pandas,然后尝试使用 to_csv。
to_export = df.toPandas()
to_export.to_csv(pathToFile, index = False)
我收到错误: [Errno 2] No such file or directory: '/dbfs/mnt/adls/Sandbox/user/project_name/testfile.csv
根据其他线程中的信息,我创建目录dbutils.fs.mkdirs("/dbfs/mnt/adls/Sandbox/user/project_name/") /n Out[40]: True
响应为真且目录存在,但我仍然遇到相同的错误。 我确信这是显而易见的事情,而且我已经盯着它看了太久以至于没有注意到。 有没有人看到我的错误可能是什么?
Python 的pandas
库仅在文件 API 格式时才识别路径(因为您使用的是挂载)。 而dbutils.fs.mkdirs
使用的Spark API 格式不同于文件 API 格式。
当您使用 dbutils.fs.mkdirs 创建目录时,路径为/dbfs/mnt/adls/Sandbox/user/project_name/
,此路径实际上将被视为dbfs:/dbfs/mnt/adls/Sandbox/user/project_name/
。 因此,该目录将在 DBFS 中创建。
dbutils.fs.mkdirs('/dbfs/mnt/repro/Sandbox/user/project_name/')
dbutils.fs.mkdirs('/mnt/repro/Sandbox/user/project_name/')
#OR
#dbutils.fs.mkdirs('dbfs:/mnt/repro/Sandbox/user/project_name/')
pdf.to_csv('/dbfs/mnt/repro/Sandbox/user/project_name/testfile.csv', index=False)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.