Groupby an numpy.array based on groupby of a pandas.DataFrame with the same length
<p>I have a numpy.array <code>arr</code> and a pandas.DataFrame <code>df</code>.</p>

<p><code>arr</code> and <code>df</code> have the same shape <code>(x,y)</code>. </p>

<p>I need to group by one column of <code>df</code> and apply the transformation of the impacted rows on <code>arr</code> which have the same shape. </p>

<p>To be clear, here is a toy example:</p>

<pre class="lang-py prettyprint-override"><code>arr = 
   0  1   12   3
   2  5   45   47
   3  19  11  111

df =
   A  B   C   D
0  0  1   2   3
1  4  5   6   7
2  4  9  10  11
</code></pre>

<p>I want to group <code>df</code> by <code>A</code> and compute the mean but in place of transforming <code>df</code> I want <code>arr</code> to be transformed. </p>

<p>So I get something like:</p>

<pre class="lang-py prettyprint-override"><code>    arr = 
        0        1         12          3
       (2+3)/2  (5+19)/2   (45+11)/2   (47+111)/2
</code></pre>

<p>Is that  possible? With no expensive loops?</p>

<p>Thanks in advance</p>