title: Pandas - Ratio between rows
body: <p>I need to find out the <strong>proportion</strong> of the elements of a column relative to a <strong>certain value in this column</strong>. For example, in this Table A I want to find out the ratio of column <em>Metric</em> regarding to the value where {<em>id1=x and id2=z</em>} of this column. Could anyone help me, please?</p>
  
  <p>For example: </p>
  
  <p>Table A</p>
  
  <pre><code>+-------+------+-------+
  | id1   | id2  | metric|
  +-------+------+-------+
  | x     |  z   | 100   |
  | x     |  w   | 10    |
  +-------+------+-------+
  </code></pre>
  
  <p>Correct Result:</p>
  
  <p>Table B</p>
  
  <pre><code>+-------+------+-------+-------+
  | id1   | id2  | metric| result|
  +-------+------+-------+-------+
  | x     |  z   | 100   |  1    | (100/100)
  | x     |  w   | 10    |  0.1  | (10/100)
  +-------+------+-------+-------+
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>d = {'id1': ['x', 'x'], 'id2': ['z','w'], 'metric': [100,10] }
  df = pd.DataFrame(data=d)
  df
  </code></pre>