[英]I would like to insert a html from result of pandas into an entire html
I hope someone will be able to help me form following issue that I am facing.我希望有人能够帮助我形成以下我面临的问题。
I just would like to insert a html from result of pandas into an entire html as below,我只想将 pandas 结果中的 html 插入到整个 html 中,如下所示,
...
df_add_html=df_add.to_html()
template="""<html>
<head></head>
<body>
Pandas : left-only<br>
I want to insert df_add_html here
</body>
</html>"""
part1=MIMEText(template. 'html')
msg.attach(part1)
...
The purpose is that I want to merge many results from pandas to a html and I will send a email with the html.目的是我想将 pandas 中的许多结果合并到 html 并且我将发送 email 和 ZFC369FDC70D82ZCA.
I hope I would get some advice from you.我希望我能得到你的一些建议。
Thanks.谢谢。
You can use standard format()
您可以使用标准
format()
template = "text {} text".format(df_add_html)
or f-string
或
f-string
template = f"text {df_add_html} text"
template = """<html>
<head></head>
<body>
Pandas : left-only<br>
{}
</body>
</html>""".format(df_add_html)
or或者
template = f"""<html>
<head></head>
<body>
Pandas : left-only<br>
{df_add_html}
</body>
</html>"""
BTW: http://pyformat.info顺便说一句: http://pyformat.info
If you need more complex templates (ie. with for
-loop or if/else
) then you can use jinja which is used to generate HTML in Flask
(but you can generate any text file)如果您需要更复杂的模板(即使用
for
-loop 或if/else
),那么您可以使用用于在Flask
中生成 HTML 的jinja (但您可以生成任何文本文件)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.