title: Faster Pandas groupby on two columns with high cardinality
body: <p>I have a portion of code that does a <code>groupby</code> over two columns, the two of which contain thousands of unique values. The dataset is made of several million rows.</p>
  <pre class="lang-py prettyprint-override"><code>gp = df.groupby(['col1', 'col2']).size()
  </code></pre>
  <p>The resulting <code>gp</code> is approx. 5-6 million rows, one for each combination of values of <code>col1</code> and <code>col2</code>.</p>
  <p>This works perfectly fine, however it is very slow (several minutes). Is there any way to achieve the same result faster?</p>
  <p>Note that I can't resort to simply spread the computation over multiple cores, as all cores are already busy (similar <code>groupby</code> operations happen in parallel over all cores, for the remaining columns).</p>