title: Chaining operators to identify value where record is closest to a number
body: <p>I have a <code>DataFrame</code> <code>df</code>:</p>
  
  <pre><code>id  Volume  time_norm   time_norm_ratio speed   BPR_free_speed  free_flow_speed capacity_speed  dev_free_flow
  9SOUTHBOUND 1474    85  1.794392523 8.947916667 17.88   16.05607477 8.028037383 0.919879283
  9SOUTHBOUND 1375    17  1.158878505 13.85483871 17.88   16.05607477 8.028037383 5.826801327
  9SOUTHBOUND 1052    22  1.205607477 13.31782946 17.88   16.05607477 8.028037383 5.289792074
  9SOUTHBOUND 986 21  1.196261682 13.421875   17.88   16.05607477 8.028037383 5.393837617
  9SOUTHBOUND 1071    15  1.140186916 14.08196721 17.88   16.05607477 8.028037383 6.05392983
  9SOUTHBOUND 1206    34  1.317757009 12.18439716 17.88   16.05607477 8.028037383 4.15635978
  9SOUTHBOUND 1222    34  1.317757009 12.18439716 17.88   16.05607477 8.028037383 4.15635978
  9SOUTHBOUND 1408    33  1.308411215 12.27142857 17.88   16.05607477 8.028037383 4.243391188
  9SOUTHBOUND 1604    69  1.644859813 9.761363636 17.88   16.05607477 8.028037383 1.733326253
  9SOUTHBOUND 1731    124 2.158878505 7.437229437 17.88   16.05607477 8.028037383 -0.590807946
  9SOUTHBOUND 1596    640 6.981308411 2.299866131 17.88   16.05607477 8.028037383 -5.728171252
  9NORTHBOUND 449 17  1.17    14.66666667 17.88   17.16   8.58    6.086666667
  9NORTHBOUND 299 17  1.17    14.66666667 17.88   17.16   8.58    6.086666667
  9NORTHBOUND 241 18  1.18    14.54237288 17.88   17.16   8.58    5.962372881
  9NORTHBOUND 164 13  1.13    15.18584071 17.88   17.16   8.58    6.605840708
  9NORTHBOUND 142 16  1.16    14.79310345 17.88   17.16   8.58    6.213103448
  9NORTHBOUND 137 15  1.15    14.92173913 17.88   17.16   8.58    6.34173913
  9NORTHBOUND 196 13  1.13    15.18584071 17.88   17.16   8.58    6.605840708
  </code></pre>
  
  <p>I wish to find the <code>volume</code> when the speed is 50% of the maximum speed for each <code>id</code>. In order to do this, I found the maximum speed (<code>free_flow_speed</code>) per id, calculated 50% of this and set it to <code>free_flow_speed</code>. In order to identify which record is closest to the 50% <code>free_flow_speed</code>, I created a <code>dev_free_flow</code> column which is the difference between the given <code>speed</code> and the <code>free_flow_speed</code>. Find the record closest to zero, for each <code>id</code>, should identify the record for which to attribute the <code>cap_design</code> value.</p>
  
  <p>Therefore I want to create a new column <code>cap_design</code> which is the <code>volume</code> when <code>diff</code> is closest to zero, for each <code>id</code>. </p>
  
  <p>From my last SO question (I'm not having a good day here) I have created:</p>
  
  <pre><code>df['cap_design'] = df['Volume'].where(df.groupby('id')['diff'].transform('min'))
  </code></pre>
  
  <p>However, this returns a <code>cap_design</code> value of the <code>Volume</code> per that row, rather than the volume of the closest to zero value for <code>dev_free_flow</code>, per <code>id</code>. How do I achieve this?</p>