def separate_cols(line):
    line = line.replace('true', '1').replace('false', '0')
vals = line.split(',')
for i, x in enumerate(vals):
    yield i, x
input = sc.textFile('train.csv', minPartitions=6).mapPartitionsWithIndex(
    drop_first_line)
pairs = input.flatMap(separate_cols)
result = pairs.groupByKey().map(lambda kv: '{0},{1}'.format(kv[0], ','.join
    (kv[1])))
result.saveAsTextFile('pythonout')
Производительность Spark для Scala и Python