Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python output

from pyspark import SparkContext
sc = SparkContext.getOrCreate()
data1 = sc.parallelize([[ 'red blue hi you red' ],
            [ 'ball green ball go four ball'],
            [ 'nice red start nice' ],
            [ 'ball no kill tree go go' ]])
data2 = data1.flatMap(lambda x: [
  (x_i,1) for xx in x for x_i in xx.split(' ')])
data3 = data2.reduceByKey(lambda x, y: x + y)
print(data3.collect())
Source by sjsu.instructure.com #
 
PREVIOUS NEXT
Tagged: #python #output
ADD COMMENT
Topic
Name
1+4 =