Differences
This shows you the differences between two versions of the page.
Both sides previous revision
Previous revision
Next revision
|
Previous revision
Next revision
Both sides next revision
|
spark:using-python [2022/12/14 12:59] straka [Usage Examples] |
spark:using-python [2022/12/14 13:00] straka [Usage Examples] |
.flatMap(lambda line: line.split()) | .flatMap(lambda line: line.split()) |
.map(lambda word: (word, 1)) | .map(lambda word: (word, 1)) |
.reduceByKey(lambda c1,c2: c1+c2) | .reduceByKey(lambda c1, c2: c1+c2) |
.sortBy(lambda word_count: word_count[1], ascending=False) | .sortBy(lambda word_count: word_count[1], ascending=False) |
.take(10)) | .take(10)) |
.flatMap(lambda line: line.split()) | .flatMap(lambda line: line.split()) |
.map(lambda token: (token, 1)) | .map(lambda token: (token, 1)) |
.reduceByKey(lambda x,y: x + y) | .reduceByKey(lambda x, y: x + y) |
.sortBy(lambda word_count: word_count[1], ascending=False) | .sortBy(lambda word_count: word_count[1], ascending=False) |
.saveAsTextFile(output)) | .saveAsTextFile(output)) |