Skip to content

Scala to Python - pairRdd folder #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Oct 2, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added pairRdd/aggregation/reducebykey/WordCount.py
  • Loading branch information
Pedro Bernardo committed Oct 2, 2017
commit 43f7883c03722e16c5b3fa0809f574240613862c
14 changes: 14 additions & 0 deletions pairRdd/aggregation/reducebykey/WordCount.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from pyspark import SparkContext

if __name__ == "__main__":

sc = SparkContext("local", "wordCounts")
sc.setLogLevel("ERROR")

lines = sc.textFile("in/word_count.text")
wordRdd = lines.flatMap(lambda line: line.split(" "))
wordPairRdd = wordRdd.map(lambda word: (word, 1))

wordCounts = wordPairRdd.reduceByKey(lambda x, y: x + y)
for word, count in wordCounts.collect():
print("{} : {}".format(word, count))