python - 即使在正确的位置提到了该文件,输入文件也不存在 - pyspark

标签 python apache-spark pyspark

我试图通过形成键值对来读取日志行,但出现错误。 这是我的代码:

logLine=sc.textFile("C:\TestLogs\testing.log").cache() 
lines = logLine.flatMap(lambda x: x.split('\n'))
rx = "(\\S+)=(\\S+)" 
line_collect = lines.collect() 
for line in line_collect :  
    d = dict([(x,y) for x,y in re.findall(rx,line)])    
    d = str(d)  
    print d

错误:

line_collect = lines.collect()......InvalidInputException: Input path does not exist: file:/C:/TestLogs esting.log

我不知道如何纠正这个问题。我是 python 和 Spark 的新手。

最佳答案

当字符序列\t在字符串中找到,它将被替换为制表符。您实际上可以在错误消息中看到这一点。

我建议始终使用正斜杠 /作为目录分隔符,即使在 Windows 上也是如此。或者在字符串前面加上 r 前缀,如下所示: r"does not replace \t with <tab>." .

您可能想阅读字符串文字:https://docs.python.org/2.0/ref/strings.html .

关于python - 即使在正确的位置提到了该文件,输入文件也不存在 - pyspark,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39200177/

相关文章:

export-to-csv - 将 Pyspark Dataframe 保存到不带标题的 csv 中

python-3.x - 如何实现自定义 Pyspark 爆炸(用于结构数组),4 列合 1 爆炸?

python - 在列表上使用求和函数时,“int”对象不可调用

python - 如何在python中删除图像的背景

python - 从文件中分段读取

scala - 如何根据数据框中的另一列添加包含星期几的新列?

pandas - 使用 Spark 版本 2.2 的 row_number() 函数创建 PySpark DataFrame 中每行的行号

sql-server - 在 pyspark 查询中使用临时表

apache-spark - PySpark - 运行进程

python - 如何用两组变量拆散 Pandas 数据框