Created
February 6, 2018 09:55
-
-
Save koushikmln/50d452c12e762e6a63a7ca8530ee3fd5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools as it, sys | |
from functools import reduce | |
order_items = open("/data/retail_db/order_items/part-00000","r").read().splitlines()[:50] | |
order_subtotal = list(map(lambda x: (int(x.split(",")[1]),float(x.split(",")[4])),order_items)) | |
#sorted values should be passed in groupby | |
iterator = it.groupby(sorted(order_subtotal),lambda x: x[0]) | |
revenuePerOrder = map(lambda x: (x[0], reduce(lambda a,b: a + b, map(lambda v: v[1], x[1]))), iterator) | |
print(list(revenuePerOrder)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment