Created
June 6, 2021 05:47
-
-
Save AdroitAnandAI/f61e2a5e7b8af20807cb608382b1f29b to your computer and use it in GitHub Desktop.
To count words
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Word Count using Spark | |
# https://spark.apache.org/examples.html | |
text_file = sc.textFile("./sample.txt") //local file | |
counts = text_file.flatMap(lambda line: line.split(" ")) \ | |
.map(lambda word: (word, 1)) \ | |
.reduceByKey(lambda a, b: a + b) | |
counts.saveAsTextFile("./count_output") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment