muk*_*iur 3 python scala apache-spark
谁能将这个非常简单的scala代码转换为python?
val words = Array("one", "two", "two", "three", "three", "three")
val wordPairsRDD = sc.parallelize(words).map(word => (word, 1))
val wordCountsWithGroup = wordPairsRDD
.groupByKey()
.map(t => (t._1, t._2.sum))
.collect()
Run Code Online (Sandbox Code Playgroud)
小智 5
尝试这个:
words = ["one", "two", "two", "three", "three", "three"]
wordPairsRDD = sc.parallelize(words).map(lambda word : (word, 1))
wordCountsWithGroup = wordPairsRDD
.groupByKey()
.map(lambda t: (t[0], sum(t[1])))
.collect()
Run Code Online (Sandbox Code Playgroud)