【发布时间】:2017-12-30 10:25:58
【问题描述】:
我在 Ubuntu 上使用 jupyter。
所以我遇到了下一个问题,这是我的代码:
from pyspark import SparkContext
sc = SparkContext.getOrCreate()
ut = sc.textFile("hdfs://localhost:54310/hduser/firstnames")
rows= ut.map(lambda line: line.split(";"))
res = rows.filter(lamda row: row[2] >= "2000" and row[2] <= "2004")
res = res.map(lambda row: ({row[1],row[2]},int(row[3])))
输出:
[({'2001', 'Brussel'}, 9),
({'2001', 'Brussel'}, 104),
({'2001', 'Vlaanderen'}, 16),
({'2002', 'Brussel'}, 12), ...]
我需要我的输出是这样的:
[({'2001', 'Brussel'}, 113),
({'2001', 'Vlaanderen'}, 16),
({'2002', 'Brussel'}, 12)]
我之前用 reduceByKey 尝试过一些事情 已经看到很多关于reduceByKey的问题,但无法弄清楚。提前致谢。
【问题讨论】:
标签: pyspark