How save list to file in spark?
takeSample()
returns array. you need parallelize it and save it.
rdd = spark_context.textFile('a.tx')
spark_context.parallelize(rdd.takeSample(False, 3)).saveAsTextFile('b.tx')
But the best way is to use sample()
(Here, I am taking 30%) which will return RDD
rdd.sample(False, 0.3).saveAsTextFile('b.tx')