Sai

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]) …

Order Count by Status Using Itertools Read More »

Cumulative Operations Using Itertools

Cumulative Operations using itertools¶ Get cumulative sales from list of transactions. In [1]: ns = [1, 2, 3, 4] # Cumulative totals [1, 3, 6, 10] # Cumulative product [1, 2, 6, 24] In [2]: import itertools as iter In [3]: iter.accumulate? Init signature: iter.accumulate(iterable, func=None, *, initial=None) Docstring: Return series of accumulated sums (or other binary function …

Cumulative Operations Using Itertools Read More »