title: Python: Color pandas dataframe based on MultiIndex
body: <p>Consider this MultiIndex dataframe</p>
  
  <pre><code>i = pd.MultiIndex.from_tuples([(0, 0), (0, 1), (1, 0), (1, 1)], names=['level_0', 'level_1'])
  df = pd.DataFrame(range(0, 4), index=i, columns=['foo'])
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/o8AcR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/o8AcR.png" alt="df"></a></p>
  
  <p>and this color dictionary</p>
  
  <pre><code>colors = {0: (0.6, 0.8, 0.8, 1), 1: (1, 0.9, 0.4, 1)}
  </code></pre>
  
  <p>where the first three items of the tuple are RGB values and the fourth item is the transparency alpha.</p>
  
  <p>How can the df be colored based on the level_0 index?</p>
  
  <p>This result would be nice to have:</p>
  
  <p><a href="https://i.stack.imgur.com/dvkXs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dvkXs.png" alt="df_level_0"></a></p>
  
  <p>But this one here I would consider fine art:</p>
  
  <p><a href="https://i.stack.imgur.com/0MatA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0MatA.png" alt="df_art"></a></p>
  
  <p>In the latter style, the lighter cells would have the same RGB settings but a transparency of 0.25.</p>