我有一个数据集如下
ID |利益
1 |骑马,阅读,烹饪
2 |骑马,跑步
3 |旅游,烹饪
是否可以检索诸如
之类的兴趣摘要 骑马,2答案 0 :(得分:0)
请在下面试试。
val firstRDD = sc.textFile("/path_to_file/file.txt").map(line =>line.split("\\|")(1))
val resultRDD=firstRDD.flatMap(line => line.split(",")).map(word => (word,1)).reduceByKey(_+_)
resultRDD.collect
这是scala shell的输出
res23: Array[(String, Int)] = Array((reading,1), (cooking,2), (travelling,1), (running,1), (riding,2))