title: How to format an html table using python
body: <p>I am trying to format an html table in my python script and then send it as an email. The table originates from a pandas dataframe which I then saved to HTML using the <code>.to_html()</code> function.</p>
  <pre><code>from email.mime.multipart import MIMEMultipart
  from email.mime.base import MIMEBase
  from email.mime.text import MIMEText
  from email import encoders
  from smtplib import SMTProm email.mime.base import MIMEBase
  from email.mime.text import MIMEText
  from email import encoders
  from smtplib import SMTP
  
  # Save dataframe to html
  df_final.to_html(r'Data/trend_report_word_3m_rolling.html',col_space = 20, index = False)
  
  #read html
  report_file = open(r'Data\trend_report_word_3m_rolling.html')
  html_excel = report_file.read()
  
  # Prepare to send email
  part_html = MIMEText(html_report, 'html')
  
  #Attach attachments to message
  msg.attach(part)
  msg.attach(part_html)
  
  # Send the message via SMTP server
  with SMTP(&quot;&quot;) as smtp:
      smtp.send_message(msg)
      #print(&quot;The email was sent to: &quot;,string_receiver)
      smtp.quit()
  </code></pre>
  <p>As far as I understand using the <code>.read()</code> function only reads the html file yet it does not allow me to edit the html?
  What I would like at the end is for the recipient of the email to see the table with formats (such as colors and specific column width).</p>
  <p>Maybe I should first format my dataframe and than save it to HTML?
  Please ask me some questions if my method is unclear.</p>
  <p>Thank you.</p>