我有一个任务要求我使用python中的mapper/reducer来完成客户数据的MapReduce。我有一个CSV文件,其中包含CustomerID、ProductID和花费的金额。第一个任务是确定每个客户的总花费,我很容易就完成了。下一部分要求我取下这个清单,并按花费总额的降序排序。我在这里挣扎。。。建议在另一个MapReduce之上使用MapReduce。以下是我的代码:
from mrjob.job import MRJob
class TotalAmountCust(MRJob):
def mapper(self, _, line):
(customerid, idno, amount) = line.split(',')
yield customerid, float(amount)
def reducer(self, customerid, amount):
yield customerid, sum(amount)
if __name__ == '__main__':
TotalAmountCust.run()
第2部分有一个问题,根本不会给我一个结果。任何建议都会被很好地推荐。。。我试图研究MRJob.SORT_值是的,但这并没有给我带来我希望的结果。在
我解决了,现在命令输出
相关问题 更多 >
编程相关推荐