如何使用 win32com 在 Python 电子邮件中插入 Pandas 变量
How to Insert Pandas Variable in Python email using win32com
您好,我正在使用以下代码以及 Pandas 和 Numpy
import win32com.client as win32
outlook = win32.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
mail.To = 'mail@domain.com'
mail.Subject = 'Test'
mail.Body = 'Message body'
mail.HTMLBody = '<html>............................</html>'
#this field is optional
# To attach a file to the email (optional):
#attachment = "Path to the attachment"
#mail.Attachments.Add(attachment)
mail.Send()
在 html 正文中,我想使用 pandas 中的一些值,例如 df.shape[0] 或 df['column'].max()甚至 variable1 = df['column'].max()
我如何在上面的代码中实现这一点,我打算在 HTML 消息中使用来自 Pandas 的值到 Outlook。
电子邮件的正文是一个字符串,因此您可以简单地使用 format
并替换任何变量,例如:
mail.HTMLBody = '<html>........variable1 is: {v}....</html>'.format(v=variable1)
您好,我正在使用以下代码以及 Pandas 和 Numpy
import win32com.client as win32
outlook = win32.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
mail.To = 'mail@domain.com'
mail.Subject = 'Test'
mail.Body = 'Message body'
mail.HTMLBody = '<html>............................</html>'
#this field is optional
# To attach a file to the email (optional):
#attachment = "Path to the attachment"
#mail.Attachments.Add(attachment)
mail.Send()
在 html 正文中,我想使用 pandas 中的一些值,例如 df.shape[0] 或 df['column'].max()甚至 variable1 = df['column'].max()
我如何在上面的代码中实现这一点,我打算在 HTML 消息中使用来自 Pandas 的值到 Outlook。
电子邮件的正文是一个字符串,因此您可以简单地使用 format
并替换任何变量,例如:
mail.HTMLBody = '<html>........variable1 is: {v}....</html>'.format(v=variable1)