-
-
Save Rahul0523/8c20ed8dd7023bab49ecbc83fbbd62ae to your computer and use it in GitHub Desktop.
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
data = sc.textFile('/public/randomtextwriter/part-m-00000') | |
wc = data. \ | |
flatMap(lambda line: line.split(' ')). \ | |
map(lambda word: (word, 1)). \ | |
reduceByKey(lambda x, y: x + y) | |
wc. \ | |
map(lambda rec: rec[0] + ',' + str(rec[1])). \ | |
saveAsTextFile('/user/training/core/wordcount') |
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
from pyspark.sql.functions import split, explode | |
data = spark.read.text('/public/randomtextwriter/part-m-00000') | |
wc = data.select(explode(split(data.value, ' ')).alias('words')). \ | |
groupBy('words'). \ | |
agg(count('words').alias('wc')) | |
wc.write.csv('/user/training/df/wordcount') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment