我有当前代码
lines = sc.textFile("file:///SparkCourse/ml-100k/u.data")
ratings = lines.map(lambda x: x.split()[2])
result = ratings.countByValue()
据此,“x”最终代表文本文件中的一行: 文本文件摘录:
196 242 3 881250949
186 302 3 891717742
22 377 1 878887116
244 51 2 880606923
166 346 1 886397596
地图为什么/如何将其拆分为每行并返回一行作为“x”?
SparkContext.textFile(name, minPartitions=None, use_unicode=True)[source]
Read a text file from HDFS, a local file system (available on all nodes), or any Hadoop-supported file system URI, and return it as an RDD of Strings
参见并且RDD.map
重新调整新的RDD,将函数应用于RDD的每个元素。在这种情况下,元素是文件中的整行。