Order Count by Status Using Itertools
Order Count by Status using itertools¶ Get count by order status using orders data set. In [1]: %run 02_preparing_data_sets.ipynb In [2]: orders[:3] Out[2]: [‘1,2013-07-25 00:00:00.0,11599,CLOSED’, ‘2,2013-07-25 00:00:00.0,256,PENDING_PAYMENT’, ‘3,2013-07-25 00:00:00.0,12111,COMPLETE’] In [3]: orders_sorted = sorted(orders, key=lambda k: k.split(‘,’)[3]) In [4]: orders_sorted[:3] Out[4]: [‘50,2013-07-25 00:00:00.0,5225,CANCELED’, ‘112,2013-07-26 00:00:00.0,5375,CANCELED’, ‘527,2013-07-28 00:00:00.0,5426,CANCELED’] In [5]: import itertools as iter In [6]: orders_grouped = iter.groupby(orders_sorted, lambda order: order.split(‘,’)[3]) …