python python-get-count-by-date-mapreduce.py

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python python-get-count-by-date-mapreduce.py相关的知识,希望对你有一定的参考价值。

import itertools as it
path = "/Users/itversity/Research/data/retail_db/orders/part-00000"
orders = open(path).read().splitlines()

ordersMap = it.imap(lambda o: (o.split(",")[1], 1), orders)
ordersGroupBy = it.groupby(sorted(ordersMap), lambda k: k[0])

def getCount(l):
    v = map(lambda k: k[1], list(l))
    return reduce(lambda tot, val: tot + val, v)

orderCountByDate = it.imap(lambda o: (o[0], getCount(o[1])), ordersGroupBy)

for i in sorted(orderCountByDate): print(i)

以上是关于python python-get-count-by-date-mapreduce.py的主要内容,如果未能解决你的问题,请参考以下文章

Python代写,Python作业代写,代写Python,代做Python

Python开发

Python,python,python

Python 介绍

Python学习之认识python

python初识