I have a dataframe, In that if the value is starting with letter "A" i'm styling it in red color, now i need to send it as html table in mail but when i execute it its coming without that styling, below is the code i tried please help. please check the image for df style
import os
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import pandas as pd
def color_failed(values):
if values.startswith("A"):
color="Red"
else:
color="yellow"
return 'color: %s' % color
def test_mail():
try:
server=smtplib.SMTP()
d={"One":["Abhi","Shek"],"two":["Arjun","Echo"],"three":["Virat","Gandalf"],"four":["Emma","Amma"]}
df=pd.DataFrame(d)
df.style.applymap(color_failed)
msg = MIMEMultipart()
msg['Subject'] = "Testing"
msg['From'] = mail_id
msg['To']=mail_id
html = """\
<html>
<head>Test Email
<style>
</style>
</head>
<body>
{0}
</body>
</html>
""".format(df.to_html())
email_body = MIMEText(html, 'html')
msg.attach(email_body)
server.sendmail(mail_id, mail_id, msg.as_string())

df.to_html()always givesHTMLwithout styles. You may add some parameters into_html(....)- but this need to read documentation for to_html(). But for more complex table you may have to format it on your own (usingfor-loops to work with every row and column separatelly).