小编use*_*102的帖子

Python3 如何在电子邮件中发送 Pandas Dataframe

def call_panda():
    filename = 'C:\\file.csv'
    cols_to_use = ['col1', 'col2', 'col3', 'col4']
    df = pd.read_csv(filename, nrows= 5,usecols=cols_to_use,index_col='col1')               
    # Send email
    me = 'me@email.com'
    you = 'you@email.com'
    textfile = df
    with open(textfile, 'rb') as fp:
        msg = MIMEText(fp.read())
        msg['Subject'] = 'Contents of file'
        msg['From'] = me
        msg['To'] = you
        s = smtplib.SMTP('mailhost.acme.net')
        s.sendmail(me, [you], msg.as_string())
        s.quit()
Run Code Online (Sandbox Code Playgroud)

错误消息是 open(textfile, 'rb') as fp: TypeError: Expected str, bytes or os.PathLike object, not DataFrame

dataframe pandas

6
推荐指数
2
解决办法
2万
查看次数

标签 统计

dataframe ×1

pandas ×1