title: pandas groupby per-group value
body: <p>I have this data:</p>
  <pre><code>df = pd.DataFrame({
      &quot;dim1&quot;:   [ &quot;aaa&quot;, &quot;aaa&quot;, &quot;aaa&quot;, &quot;aaa&quot;, &quot;aaa&quot;, &quot;aaa&quot; ],
      &quot;dim2&quot;:   [ &quot;xxx&quot;, &quot;xxx&quot;, &quot;xxx&quot;, &quot;yyy&quot;, &quot;yyy&quot;, &quot;yyy&quot; ],
      &quot;iter&quot;:   [     0,     1,     2,     0,     1,     2 ],
      &quot;value1&quot;: [   100,   101,    99,   500,   490,   510 ],
      &quot;value2&quot;: [ 10000, 10100,  9900, 50000, 49000, 51000 ],
  })
  </code></pre>
  <p>I then <code>groupby</code> dim1/dim2 and out of all iterations, I pick value1/value2 for the minimum value1:</p>
  <pre><code>df = df.groupby([&quot;dim1&quot;, &quot;dim2&quot;], group_keys=False) \
      .apply(lambda x: x.sort_values(&quot;value1&quot;).head(1)).drop(columns=[&quot;iter&quot;])
  </code></pre>
  <p>which returns:</p>
  <pre><code>dim1    dim2    value1  value2
   aaa    xxx         99    9900
   aaa    yyy        490   49000
  </code></pre>
  <p>My question: how can I add a new column that contains the min value1 per dim1 group:</p>
  <pre><code>dim1    dim2    value1  value2     new_col
   aaa    xxx         99    9900          99
   aaa    yyy        490   49000          99
  </code></pre>
  <p>I tried something like this, which didn't work:</p>
  <pre><code>df[&quot;new_col&quot;] = df.groupby([&quot;dim1&quot;], group_keys=False) \
      .apply(lambda x: x.value1.head(1))
  </code></pre>