I left the following comment at the blog:
For this example, idiomatic Pandas would look like this:
def gen_stats_pandas2(dataset_pandas):
grouped = dataset_pandas.groupby('product_id')
stats = grouped.aggregate(['count', 'sum', 'mean'])
return stats[[('product_order_num','count'), ('quantity','sum'), ('price','mean')]]
which is simpler and about 500x faster than gen_stats_pandas() in the example:
%%time
res1 = gen_stats_pandas(dataset_pandas)
CPU times: user 8.48 s, sys: 32 ms, total: 8.51 s
Wall time: 8.58 s
%%time
res2 = gen_stats_pandas2(dataset_pandas)
CPU times: user 16 ms, sys: 4 ms, total: 20 ms
Wall time: 17.6 ms
For this example, idiomatic Pandas would look like this:
which is simpler and about 500x faster than gen_stats_pandas() in the example: