首页 > 解决方案 > pandas html 函数转换为浮点数

问题描述

我有一个 df,我正在将其转换为 HTML 以作为电子邮件附件发送。

电子邮件功能:-

def send_email(text,html,me,you):
    #me = "test@gmail.com"
    #you = "test@test.com"

    # Create message container - the correct MIME type is multipart/alternative.
    msg = MIMEMultipart('alternative')
    msg['Subject'] = "Link"
    msg['From'] = me
    msg['To'] = you

    # Record the MIME types of both parts - text/plain and text/html.
    part1 = MIMEText(text, 'plain')
    part2 = MIMEText(html, 'html')

    # Attach parts into message container.
    # According to RFC 2046, the last part of a multipart message, in this case
    # the HTML message, is best and preferred.
    msg.attach(part1)
    msg.attach(part2)

    # Send the message via local SMTP server.
    s = smtplib.SMTP('localhost')
    # sendmail function takes 3 arguments: sender's address, recipient's address
    # and message to send - here it is sent as one string.
    s.sendmail(me, you, msg.as_string())

之后,我将我的 DF 转换为 HTML:-

text = "below is the data"
html = df.to_html()

它将所有数字字段转换为浮点数。我怎样才能避免这种情况?

标签: pythonpandasdataframe

解决方案


推荐阅读