Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用python格式化html表_Html_Python 3.x_Pandas_Html Email - Fatal编程技术网

如何使用python格式化html表

如何使用python格式化html表,html,python-3.x,pandas,html-email,Html,Python 3.x,Pandas,Html Email,我试图在python脚本中格式化html表,然后将其作为电子邮件发送。该表源自一个pandas数据框,然后我使用.to_HTML()函数将其保存为HTML 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 SMTP

我试图在python脚本中格式化html表,然后将其作为电子邮件发送。该表源自一个pandas数据框,然后我使用
.to_HTML()
函数将其保存为HTML

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 Henkel's SMTP server
with SMTP("") as smtp:
    smtp.send_message(msg)
    #print("The email was sent to: ",string_receiver)
    smtp.quit()
据我所知,使用
.read()
函数只读取html文件,但它不允许我编辑html? 最后,我想让邮件收件人看到表格的格式(例如颜色和特定列宽)

也许我应该先格式化数据帧,然后将其保存到HTML? 如果我的方法不清楚,请问我一些问题


谢谢。

您需要一个html模板模块,例如:

或小胡子(简单小巧的模板系统):


“我希望能够格式化html表格”。听起来很有趣。格式是一个非常模糊的术语,你到底想要什么格式?你目前得到了什么?你期望得到什么?我们无法轻松解决您的问题,因为我们无法运行它。请把你的问题改写成一个问题。