title: How to style a pandas DataFrame into an excel file
body: <p>I am trying to build an application which writes data into an excel file. I am therefore trying to use the <code>pandas</code> library and I use the <code>xlsxwriter</code> engine. I read the documentation about the <code>Styler</code> object from the pandas library, but I can't find out a way to modify the style of table headers (or column headers, the keys of the dictionary I feed to the DataFrame constructor). In fact, I think the <code>set_table_styles</code> method isn't working very well in my case.</p>
  <p>Here is the code I run:</p>
  <pre class="lang-py prettyprint-override"><code>import os
  import pandas
  
  writer = pandas.ExcelWriter(f&quot;{os.getcwd()}\\Styled_excel.xlsx&quot;, engine=&quot;xlsxwriter&quot;, mode='w')
  
  data_frame = pandas.DataFrame({&quot;Pressure&quot;: [10, 20, 30, 50],
                                 &quot;Volume&quot;: [10, 8, 5, 2]})
  
  styler = data_frame.style
  styler.set_properties(**{'color': 'red', 'border-color': 'black', 'border-width': &quot;1px&quot;})
  styler.set_table_styles([{'selector': 'th', 'props': [('font-weight', 'normal')]}])
  
  styler.to_excel(excel_writer=writer, sheet_name=&quot;Feuil1&quot;, startrow=4, startcol=2, index=False)
  
  writer.save()
  </code></pre>
  <p>Although the <code>set_properties</code> works as expected, <code>set_table_styles</code> doesn't seem to apply the style I want to, which is a normal font weight for the cells containing &quot;Pressure&quot; and &quot;Volume&quot;.</p>
  <p>On the same topic, I can't find anywhere in the documentation a way to programmatically change the width of a column, is it just not supported?</p>
  <p>If you have any clue on what I might be doing wrong or why it isn't working, I thank you in advance for your answer.</p>
  <p>Paul</p>
  <p>EDIT: I did find an answer to the issues I had but if someone has an explanation as to why my previous code wasn't working as expected, I'll be glad to hear it (but I think it's due to the fact that the <code>set_table_styles</code> method can only be used when rendering an html page or when displaying the table in Jupyter Notebook)</p>