Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在电子邮件中删除python中的nan_Python_Email_Nan - Fatal编程技术网

在电子邮件中删除python中的nan

在电子邮件中删除python中的nan,python,email,nan,Python,Email,Nan,我已经用python创建了一封自动电子邮件。现在,我正在尝试删除电子邮件中的nan详细信息,因为用户不希望nan出现在电子邮件中。我不知道怎么做。有人能帮我添加或编辑下面的代码吗 这是我的代码: import pandas as pd import csv from tabulate import tabulate from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText import

我已经用python创建了一封自动电子邮件。现在,我正在尝试删除电子邮件中的nan详细信息,因为用户不希望nan出现在电子邮件中。我不知道怎么做。有人能帮我添加或编辑下面的代码吗
这是我的代码:

import pandas as pd
import csv
from tabulate import tabulate
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import smtplib

user= 'mahirah.abd.wahab@ericsson.com'
password = '--------'
server = 'smtp.office365.com:587'
recipient = 'nur.suraya.shazwani.kamaru.zaman@ericsson.com,mahirah.abd.wahab@ericsson.com'

text = """
This is a test for the data to be sent

{table}

Regards,

Me"""

html = """
<html>
<head>
<style>
 This is a test auto generated email 
 table, th, td {{ border: 1px solid black; border-collapse: collapse; }}
  th, td {{ padding: 5px; }}
</style>
</head>
<body>
{table}
<p></p>
<p></p>
</body></html>
"""

# with open('input.csv') as input_file:
#     reader = csv.reader(input_file)
#     data = list(reader)

df = pd.read_csv('testcsv2.csv')
col_list = list(df.columns.values)
to_drop = []
for i in range(len(df)):
    if df['HOSS1 REVIEWED DATE'][i] == 'nan':
        to_drop.append(i)
df.drop(df.index[to_drop])
df.reset_index(drop=True, inplace=True)
data = df


# above line took every col inside csv as list
text = text.format(table=tabulate(data, headers=col_list, tablefmt="grid"))
html = html.format(table=tabulate(data, headers=col_list, tablefmt="html"))

message = MIMEMultipart(
    "alternative", None, [MIMEText(text), MIMEText(html,'html')])

message['Subject'] = "Rental PR – Pending HOS Approval"
message['From'] = user
message['To'] = recipient
server = smtplib.SMTP(server)
server.ehlo()
server.starttls()
server.login(user, password)
server.sendmail(user, recipient, message.as_string())
server.quit()
将熊猫作为pd导入
导入csv
从表格导入表格
从email.mime.multipart导入MIMEMultipart
从email.mime.text导入MIMEText
导入smtplib
user='mahirah.abd。wahab@ericsson.com'
密码='----------'
服务器='smtp.office365.com:587'
收件人='nur.suraya.shazwani.kamaru。zaman@ericsson.com,mahirah.abd。wahab@ericsson.com'
text=”“”
这是对要发送的数据的测试
{table}
当做
“我”
html=”“”
这是一封测试自动生成的电子邮件
表,th,td{{边框:1px纯黑色;边框折叠:折叠;}
th,td{{padding:5px;}}
{table}

""" #打开('input.csv')作为输入文件: #reader=csv.reader(输入文件) #数据=列表(读卡器) df=pd.read\u csv('testcsv2.csv') col_list=list(df.columns.values) 到_drop=[] 对于范围内的i(len(df)): 如果df[‘HOSS1审核日期’][i]==‘nan’: 删除。追加(i) df.drop(df.index[to_drop]) df.reset_索引(drop=True,inplace=True) 数据=df #上面的行将csv中的每个列作为列表 text=text.format(table=tablete(数据,标题=col_列表,tablefmt=“grid”)) html=html.format(table=tablete(数据,标题=col_列表,tablefmt=“html”)) message=MIMEMultipart( “可选”,无,[MIMEText(text),MIMEText(html,'html')) 消息['Subject']=“租金请购单-待批准居屋” 消息['From']=用户 邮件['To']=收件人 server=smtplib.SMTP(服务器) server.ehlo() server.starttls() 服务器登录(用户、密码) server.sendmail(用户、收件人、邮件.as_string()) server.quit()
我也尝试过使用这一行代码,但仍然不起作用:

df=pd.dropna(子集=['HOSS1审核日期']

如果有人能帮忙,我将不胜感激。

试试这个

to_drop = []
for i in range(len(df)):
    if df['HOSS1 REVIEWED DATE'][i] == 'nan':
        to_drop.append(i)
df.drop(df.index[to_drop], inplace=True)
df.reset_index(drop=True, inplace=True)

“HOSS1审查日期”一栏中的数据类型是什么?列中的数据类型是Date抱歉,我是指数据框中的nan类型…是str吗?没关系,这是str,因为类型是str dropna不起作用…据我所知,有多种方法可以使用nan删除行,在HOSS1 REVIDED DATE列中循环并获取具有nan值的行索引,然后删除并重置,或者您可以使用numpy模块将nan转换为nan,然后使用dropna删除行。@Hippiepina请立即尝试。我忘了放在原处的paramHi,它仍然不工作,你能检查上面吗,我放在正确的地方了吗?有错误吗?如果是这样,那又是什么呢?您是否在df.drop中插入了inplace=True参数?