scala - 如何在 spark scala 中删除换行符
问题描述
下面的代码在 python 中运行良好。我很难在 scala 中编写等效代码
map(lambda x:x[1].replace("\n","|"))
Scala中的等效代码是什么?
我试图在 Scala 中运行以下命令并得到以下错误。
scala> val read_rdd=sc.wholeTextFiles("/user/test/test1.txt").map(x => x[1].replace("\n","\u001F"))
<console>:1: error: identifier expected but integer literal found.
解决方案
sc.wholeTextFiles() 返回 scala 元组(字符串,字符串)。要访问成员,请使用 x._1 和 x._2。
val read_rdd=sc.wholeTextFiles("e_edge.csv").map(x => x._2.replace("\n","\u001F"))
推荐阅读
- python - 如何在 Python 中将字符串“3x a;2x b”转换为字符串“aaab b”?
- django - 如何锚定 django 页面的一部分?
- r - 通过添加列/向量来更新 R 中的文件
- c# - 使用自定义属性从 C# 中的引用项目初始化主类中的自定义属性
- python - 更优雅的装箱方式
- python - 在多索引数据框中添加缺失日期索引
- java - 是否可以使用 java -cp 运行不在包中的类
- graphite - Graphite 未显示最近的数据
- ruby - Chef - 读出节点属性并将其存储在同一厨师客户端运行中的另一个节点属性中失败
- java - 如何自定义材质组件的日期范围选择器的颜色和其他内容?