我正在使用数据块在 Python 中进行练习
我正在尝试通过以下方式加载 Windows 文件:
diamonds = spark.read.csv('file:///C:/abc.csv', header="true", inferSchema="true")
我确定我的文件在 C:/abc.csv 但系统总是返回这个错误:
u'Path does not exist file:/C:/abc.csv;'
如何在windows系统中加载文件?
1. 将完整路径定义为变量 - 如果是本地路径,则每个路径都应以驱动器开头
# remove the 'file' string and use 'r' or 'u' prefix to indicate raw/unicore string format
# Option 1
PATH = r'C:\abc.csv' # raw string
# Option 2
PATH = u'C:\\abc.csv' # unicode string
2. 将路径变量设置为您的 spark 调用
diamonds = spark.read.csv(PATH, header="true", inferSchema="true")
本质上,您的文件路径是错误的。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句