title: Python - write Pandas data frame into body of email
body: <p>I'm trying to export the contents of a Pandas data frame into the body of an email. I tried to use the pandas.DataFrame.to_html method to generate the relevant html code for the table, but this hasn't worked.</p>
  
  <pre><code>text_body = "Text"    
  head_style = '&lt;style&gt;&lt;/style&gt;'
  titles = '&lt;h2&gt;Upcoming events&lt;/h2&gt;'
  data_html = df_events.to_html
  html_body = '&lt;html&gt;' + head_style + '&lt;body&gt;' + titles + data_html + '&lt;/body&gt;&lt;/html&gt;'
  
  # Add body to email
  part1 = MIMEText(html_body, 'html')
  part2 = MIMEText(text_body, 'plain')
  message.attach(part1)
  message.attach(part2)
  </code></pre>
  
  <p>The error message is, in a nutshell, that 'data_html' is a "method" and not a string and therefore cannot be concatenated to form 'html_body'. I am at a loss to what to do. Any ideas?</p>
  
  <p>P.S. I am using Python 3.7.2 via the Anaconda distribution.</p>