如何解决如何在发送电子邮件的 Python 代码中连接 2 个表
我编写了一个代码,将数据帧转换为 html 并通过电子邮件发送。我需要将这个表与另一个表(一个在另一个之上)联合/附加。有人可以帮我弄清楚我会怎么做吗?
这是我的代码:
# 'dataset' holds the input data for this script import pandas
from email.mime.text import MIMEText from email.mime.application import MIMEApplication from email.mime.multipart import MIMEMultipart from smtplib import SMTP import smtplib import sys
msg = MIMEMultipart() msg['Subject'] = "Daily Report" msg['From'] = 'MM@gmail.com'
html = """\ <html> <head></head> <body>
{0} </body> </html> "Name" """.format(pandas.DataFrame(dataset).to_html())
part1 = MIMEText(html,'html') msg.attach(part1)
server = smtplib.SMTP_SSL("smtp.gmail.com",465) server.login('MM@gmail.com','pythontest') server.sendmail("Sender@gmail.com","Receiver@python.com",msg.as_string()) server.quit()*
解决方法
您可以使用 pandas 连接表格,然后在电子邮件中使用连接结果。请参阅 pandas concat https://pandas.pydata.org/pandas-docs/stable/user_guide/merging.html
的链接版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。