AttributeError:“Series”对象在发送电子邮件时没有属性“split”错误

Hum*_*mer 3 python smtp pandas

我该如何解决以下错误。测试邮件中用分号分隔的消息如下?理想情况下,我应该从测试中的相应电子邮件发送电子邮件。

测试

SENDFROM        Test 
xx@gmail.com  xxxx@vvv.com;yyy@gggfg.com;tiitioo@ggg.com
yy@xxx.com     ggg@vvv.com;yyy@gggfg.com;vvv@ggg.com
Run Code Online (Sandbox Code Playgroud)
AttributeError: 'Series' object has no attribute 'split'
Run Code Online (Sandbox Code Playgroud)

我的代码如下:

import smtplib, ssl
from email.message import EmailMessage
import getpass
email_pass = getpass.getpass() #Office 365 password 
# email_pass = input() #Office 365 password 
context=ssl.create_default_context()
for idx, row in test.iterrows():
    
    emails = test['Test']
    sender_list  = test["SENDFROM"]
    
    smtp_ssl_host = 'smtp.office365.com'
    smtp_ssl_port = 587
    email_login = "xx@xx.com"
    email_from = sender_list
    email_to = emails
    msg2 = MIMEMultipart()
    msg2['Subject'] = "xxx"
    msg2['From'] = sender_list

    msg2['To'] = ", ".join(email_to.split(";"))
    msg2['X-Priority'] = '2'

    text = ("xxxx")
        
    msg2.attach(MIMEText(text))
    s2 = smtplib.SMTP(smtp_ssl_host, smtp_ssl_port)
    s2.starttls(context=context)
    s2.login(email_login, email_pass) 

      
    s2.send_message(msg2)
        
    s2.quit()        
Run Code Online (Sandbox Code Playgroud)

Hen*_*ker 13

让我们尝试str.splitstr.join

import pandas as pd

df = pd.DataFrame({'SENDFROM': {0: 'xx@gmail.com', 1: 'yy@xxx.com'},
                   'Test': {0: 'xxxx@vvv.com;yyy@gggfg.com;tiitioo@ggg.com',
                            1: 'ggg@vvv.com;yyy@gggfg.com;vvv@ggg.com'}})

# Use str.split and str.join and astype
df['Test'] = df['Test'].str.split(';').str.join(',')

print(df.to_string())
Run Code Online (Sandbox Code Playgroud)

输出:

       SENDFROM                                        Test
0  xx@gmail.com  xxxx@vvv.com,yyy@gggfg.com,tiitioo@ggg.com
1    yy@xxx.com       ggg@vvv.com,yyy@gggfg.com,vvv@ggg.com
Run Code Online (Sandbox Code Playgroud)