title: How to send Pandas DataFrame as an attachment in Pandas
body: <p>I have searched around SO and Google a lot but did not get my answer hence ultimately thought to ask here.</p>
  
  <p>I have a <em>csv</em> file, which I'm converting to an <em>html</em> frame which works fine and I can send that as an <em>html</em> frame via Outlook as an email.</p>
  
  <p>Was looking if we can directly send <code>df.to_html</code> as an attachment to the e-mail ?</p>
  
  <h2>Below is the code:</h2>
  
  <p>This works fine sending as an e-mail with html frame via Outlook.</p>
  
  <pre><code>import pandas as pd
  import numpy as np
  import smtplib
  from email.mime.multipart import MIMEMultipart
  from email.mime.text import MIMEText
  
  
  df = pd.read_csv('graph.csv', names=['Volume_Path', 'Last Acced', 'Year', 'Month', 'Days', '1-24 hrs', '1 hour', '15 mins', 'future'])
  df['Volume_Path'] = df['Volume_Path'].str.replace('\t', '')
  df = df.replace(np.nan, '')
  
  # Create message container - the correct MIME type is multipart/alternative.
  ##############################################################################
  msg =  "&lt;u&gt;&lt;b&gt; Checklist&lt;/b&gt;&lt;/u&gt;&lt;br /&gt;"
  msg = msg + "&lt;br /&gt;"
  msg += df.to_html(escape=False)
  def mail(msg,recipients,key):
          try:
              s = smtplib.SMTP('mailserver.xyz.com')
              msg1 = MIMEText(msg, 'html')
              sender = 'tina@xyz.com'
              msg1['From'] = sender
              msg1['To'] = ", ".join(recipients)
              msg1['Cc'] =  'mauj@xyz.com'
              msg1['Subject'] = "Mauj Test"
              s.sendmail(sender, recipients, msg1.as_string())
              print(f"Mail Sent to {sender}")
          except Exception as error:
              print(f"Mail Failed - {error}")
  recipients = ['joe@xyz.com']
  key=""
  mail(msg,recipients,key)
  </code></pre>