title: Python Pandas Pivot Table - Adding calculated column to multi-index column
body: <p>I have the following pivot table, which is a multi-index, for both the indices and the columns:</p>
  
  <pre><code>Category        HF                      DA      
                  tafp    tap     tw      tafp    tap     tafp
  ATTR    EL                      
  attr1   1.0     10      25      15      100     150     50
  attr2   2.0     0       0       0       40      70      30
          3.0     20      50      30      0       0       0
  attr3   2.0     0       0       0       0       0       0
  </code></pre>
  
  <p>Here's a dict of this pivot table (values are a bit different, but that doesn't matter):</p>
  
  <pre><code>{
  ('HF', 'tafp'): {('attr1', '1.0'): 10, ('attr2', '2.0'): 100, ('attr3','2.0'): 0, ('attr4', '2.0'): 0, ('attr2', '3.0'): 71},
  ('HF', 'tap'): {('attr1', '1.0'): 30, ('attr2', '2.0'): 350, ('attr3', '2.0'): 0, ('attr4', '2.0'): 0, ('attr2', '3.0'): 1042},
  ('HF', 'tw'): {('attr1', '1.0'): 20, ('attr2', '2.0'): 250, ('attr3', '2.0'): 0, ('attr4', '2.0'): 0, ('attr2', '3.0'): 971},
  ('DA', 'tafp'): {('attr1', '1.0'): 0, ('attr2', '2.0'): 435, ('attr3', '2.0'): 0, ('attr4', '2.0'): 0, ('attr2', '3.0'): 0},
  ('DA', 'tap'): {('attr1', '1.0'): 0, ('attr2', '2.0'): 635, ('attr3', '2.0'): 0, ('attr4', '2.0'): 0, ('attr2', '3.0'): 0},
  ('DA', 'tw'): {('attr1', '1.0'): 0, ('attr2', '2.0'): 200, ('attr3', '2.0'): 0, ('attr4', '2.0'): 0, ('attr2', '3.0'): 0}
  }
  </code></pre>
  
  <p>What I want to get in the end, is the following:</p>
  
  <pre><code>Category        HF                      DA      
                  tafp/tap    tw      tafp/tap    tafp
  ATTR    EL                      
  attr1   1.0     0.67        15      0.67        50
  attr2   2.0     0           0       0.57        30
          3.0     0.67        30      0           0
  attr3   2.0     0           0       0           0
  </code></pre>
  
  <p>So I would like to get the percentage of tafp/tap and only keep this calculated column, i.e. delete the original columns.</p>
  
  <p>Does somebody have an idea how I can achieve this? </p>
  
  <p>Any help is much appreciated :)</p>