title: Python formatting DataFrame table colours and borders
body: <p>I am trying to format my python DataFrame table's colours and borders. I am especially having difficulty formatting the top left corner colour, and borders around an entire row rather than individual cells.</p>
  <p><strong>Here is the code for the table I have now:</strong></p>
  <pre><code># create a table summary
  index = pd.MultiIndex.from_tuples([(&quot;Type&quot;, ''), (&quot;alpha&quot;, &quot;x&quot;), 
                             (&quot;alpha&quot;, &quot;y&quot;),
                             (&quot;alpha&quot;,&quot;z&quot;),
                              (&quot;beta&quot;, '')])
  
  data = [['a', 'b', 'c', 'd'],
          [1, 2, 3, 4], 
          [5, 6, 7, 8], 
          [9, 10, 11, 12],
          [13, 14, 15, 16]]
  
  table = pd.DataFrame(data = data, 
                        index = index,
                        columns =  pd.MultiIndex.from_product([['data'], ['', '  ', '   ', '    ']]))
  
  
  # set styles
  styles=[{'selector':'th','props': [
          ('vertical-align','center'),
          ('text-align', 'center'), 
          ('font-size', '12px')]}, 
          
          {'selector': 'caption','props': [
          ('color', 'black'),
          ('font-size', '10px'), 
          ('font-weight', 'bold'),
          ('caption-side', 'bottom')]}, 
         
          {'selector': 'th:not(.index_name)', 'props': [
          ('background-color', 'lightblue'), 
          ('color', 'white')]}, 
         
          {'selector': 'th.col_heading.level0', 'props': [
          ('font-size', '15px'), 
          ('background-color', 'darkblue'),
          (&quot;border&quot;, &quot;1px solid darkblue&quot;)]},
  
          {'selector': 'th.col_heading.level1', 'props': [
          ('background-color', 'darkblue'),
          (&quot;border&quot;, &quot;1px solid darkblue&quot;)]},
          
          {'selector': 'td:hover', 'props': [
          ('background-color', '#ffffb3')]}, 
         
          {&quot;selector&quot;: &quot;th&quot;, &quot;props&quot;: [
          (&quot;border&quot;, &quot;1px solid lightblue&quot;)]},
         
          {&quot;selector&quot; :&quot;.row0&quot;, &quot;props&quot;: [
          (&quot;border&quot;,&quot;2px solid darkblue&quot;),
          ('background-color', 'lightblue'), 
          ('color', 'white'),
          ('font-weight', 'bold')]}]
  
  
  table = table.style.set_caption(&quot;Some Caption&quot;).set_table_styles(styles)
  
  table
  </code></pre>
  <p><strong>The table the code produces:</strong></p>
  <p><a href="https://i.stack.imgur.com/zCbLs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zCbLs.png" alt="code table" /></a></p>
  <p><strong>The table I would like to produce:</strong></p>
  <p><a href="https://i.stack.imgur.com/Mvx7M.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Mvx7M.png" alt="table I would like" /></a></p>
  <p><strong>EDIT: code and result using answer below:</strong></p>
  <pre><code># create a table summary
  index = pd.MultiIndex.from_tuples([(&quot;Type&quot;, ''), (&quot;alpha&quot;, &quot;x&quot;), 
                             (&quot;alpha&quot;, &quot;y&quot;),
                             (&quot;alpha&quot;,&quot;z&quot;),
                              (&quot;beta&quot;, '')])
  
  data = [['a', 'b', 'c', 'd'],
          [1, 2, 3, 4], 
          [5, 6, 7, 8], 
          [9, 10, 11, 12],
          [13, 14, 15, 16]]
  
  table = pd.DataFrame(data = data, 
                        index = index,
                        columns =  pd.MultiIndex.from_product([['data'], ['', ' ', '  ', '   ']]))
  
  # set styles
  header = {'selector': 'th', 'props': 
            [('background-color', '#00008b'), ('color', 'white'), ('text-align', 'center'), ('vertical-align', 'centre'), ('font-weight', 'bold')]}
  
  header_level0 = {'selector': 'th.col_heading.level0', 'props': [('font-size', '15px')]}
  
  index = {'selector': 'th.row_heading', 'props': 
           [('background-color', '#5b9bd5'), ('color', 'white'), ('text-align', 'center'), ('font-weight', 'bold')]}
  
  top_row = {'selector': 'td.data.row0', 'props': 
           [('background-color', '#5b9bd5'), ('color', 'white'), ('text-align', 'center'), ('font-weight', 'bold')]}
  
  borders_bottom1 = {'selector': '.row0', 'props': 
                    [('border-bottom', '1px solid #00008b'), ('border-top', '1px solid #00008b')]}
  
  borders_bottom2 = {'selector': '.row_heading.level0.row1', 'props': 
                    [('border-bottom', '1px solid #00008b')]}
  
  borders_bottom3 = {'selector': '.row3', 'props': 
                    [('border-bottom', '1px solid #00008b')]}
  
  borders_bottom4 = {'selector': '.row1', 'props': 
                    [('border-bottom', '1px dashed #00008b')]}
  
  borders_bottom5 = {'selector': '.row2', 'props': 
                    [('border-bottom', '1px dashed #00008b')]}
  
  borders_right = {'selector': '.row_heading.level1', 'props': 
                   [('border-right', '1px solid #00008b')]}
  
  # apply styles
  table = table.style.set_table_styles([header, header_level0, index, top_row, borders_bottom1, borders_bottom2, borders_bottom3, borders_bottom4, borders_bottom5, borders_right])
  
  table
  </code></pre>
  <p><a href="https://i.stack.imgur.com/Vw5mf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Vw5mf.png" alt="table using answer" /></a></p>