我正在使用python从CSV文件导入数据。我过滤了一些行并收集了其余数据,然后将它们保存在数据帧中。之后,我将它们导出到html邮件正文并发送。我使用df.to html()制作了HTML正文。但是邮件没有完整的数据,多列的某些句子被删减了。为什么会发生?以及如何摆脱它?
结果:
假设 Commentlist [1] ='这是一个例子。和 Commentlist [2] ='这是另一个例子',
我会收到一封邮件,
评论[1] ='这是一个...' Comment [2] ='这是...'
我得到以下代码的结果:
with open('sample.csv','r') as csvfile:
readCSV=csv.reader(csvfile,delimiter=',')
holdtimelist=[] #list declaration
commentlist=[]
problemtypelist=[]
next(readCSV, None) #to skip header
with open('new_csv.csv','w',newline='') as newcsv: #creating new_csv
write_csv=csv.writer(newcsv,delimiter=',')
for row in readCSV:
holdtime=float(row[33]) #group hold time from excel
comment=row[3]
problemtype=row[7]
if holdtime>=10:
holdtimelist.append(holdtime)
commentlist.append(comment)
problemtypelist.append(problemType)
else:
print ("There is no delay.")
df1=pd.DataFrame(list(zip( commentlist,problemtypelist,holdtimelist)),
columns=[ 'Problem Details','Problem Type','Holding Time
(Days)'])
df1.index=df1.index+1
print(df1.size)
if df1.size==0:
print("DF1 has no Delay")
else:
subject = 'DF1'
body = '<html><body>' + 'Please See the Below Chart'+ df1.to_html() +
'</body></html>'
recipient = 'receiver@gmail.com'
#Create and send email
olMailItem = 0x0
obj = win32com.client.Dispatch("Outlook.Application")
newMail = obj.CreateItem(olMailItem)
newMail.Subject = subject
newMail.Cc=''
newMail.HTMLBody = body
newMail.To = recipient
newMail.Send()