Created
July 28, 2018 15:18
-
-
Save nithyadurai87/1c3d78918762740140bcd4d07297cb10 to your computer and use it in GitHub Desktop.
counting.py - for spark tutorial
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 import SparkConf, SparkContext | |
conf = SparkConf().setMaster("local").setAppName("WordCount") | |
sc = SparkContext(conf = conf) | |
rdd1 = sc.textFile("file:///home/shrini/smp.csv") | |
def cols(data): | |
sno,fname,lname,age,desig,mob,location = data.split(",") | |
return sno,fname,lname,age,desig,mob,location | |
dict1 = rdd1.countByValue() | |
dict2 = rdd1.map(cols).filter(lambda line: int(line[3])>=30).countByValue() | |
managers=0 | |
for i,j in dict1.items(): | |
if "Manager" in i: | |
managers = managers+j | |
seniors=0 | |
for j in dict2.values(): | |
seniors = seniors+j | |
print("Total No. of records:",str(rdd1.count())) | |
print("Distinct records:",str(rdd1.distinct().count())) | |
print("Toal No.of Managers:",str(managers)) | |
print("No. of Seniors (age>30):",str(seniors)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment