I am working on to get count out number of occurence in a file.
RDD1 = RDD.flatMap(lambda x:x.split('|'))
RDD2 = RDD1.countByValue()
I want to save the output of RDD2 to textfile.
i am able to see output by
for x,y in RDD2.items():print(x,y)
but when tried to save to textfile using RDD2.saveAsTextFile(\path) it is not working.
it was throwing as 'AttributeError: 'collections.defaultdict' object has no attribute 'saveAsTextFile''
Can you please help me understanding if i am missing something here. Or how to save countByValue to text file