Data Science: Performance of Python vs. Pandas vs. Numpy
I left the following comment at the blog:<p>For this example, idiomatic Pandas would look like this:<p><pre><code>  def gen_stats_pandas2(dataset_pandas):
      grouped = dataset_pandas.groupby(&#x27;product_id&#x27;)
      stats = grouped.aggregate([&#x27;count&#x27;, &#x27;sum&#x27;, &#x27;mean&#x27;])
      return stats[[(&#x27;product_order_num&#x27;,&#x27;count&#x27;), (&#x27;quantity&#x27;,&#x27;sum&#x27;), (&#x27;price&#x27;,&#x27;mean&#x27;)]]

</code></pre>
which is simpler and about 500x faster than gen_stats_pandas() in the example:<p><pre><code>  %%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</code></pre>