pandas groupby transform behaving differently with seemingly equivalent representations
<p>consider the <code>df</code></p>

<pre><code>df = pd.DataFrame(dict(A=['a', 'a'], B=[0, 1]))
</code></pre>

<p>I expected the following two formulations to be equivalent.</p>

<p><strong><em>formulation 1</em></strong>  </p>

<pre><code>df.groupby('A').transform(np.mean)
</code></pre>

<p><a href="https://i.stack.imgur.com/euRkW.png" rel="nofollow"><img src="https://i.stack.imgur.com/euRkW.png" alt="enter image description here"></a></p>

<p><strong><em>formulation 2</em></strong></p>

<pre><code>df.groupby('A').transform(lambda x: np.mean(x))
</code></pre>

<p><a href="https://i.stack.imgur.com/18pe5.png" rel="nofollow"><img src="https://i.stack.imgur.com/18pe5.png" alt="enter image description here"></a></p>

<p>I'd consider the results from <strong><em>formulation 2</em></strong> incorrect.  But before I go crying <em>bug</em> maybe someone has a rational explanation for it.</p>

<p>It looks like a bug to me:</p>

<pre><code>In [19]: df.groupby('A').transform(lambda x: x.sum())
Out[19]:
   B
0  1
1  1

In [20]: df.groupby('A').transform(lambda x: len(x))
Out[20]:
   B
0  2
1  2

In [21]: df.groupby('A').transform(lambda x: x.sum()/len(x))
Out[21]:
   B
0  0
1  0
</code></pre>

<p>PS Pandas version: 0.19.0</p>

python pandas