这些工作的主要思想是从分页(它有152页)中解析每个页面,并将这些数据放入db。发生运行错误时,列'execution_period'不能为空”。 在我的DataFrame中,我这样做:
df['Срок исполнения'] = df['Срок исполнения'].fillna(0)
df['Дата принятия решения/дела'] = df['Дата принятия решения/дела'].fillna(0)
不知道如何解决。
df = pd.DataFrame()
df_list = pd.read_html('sanction.xls')
df = df_list[0]
database = MySQLdb.connect (host="host", user = "root", passwd = "password", db = "db", charset='utf8')
mycursor = database.cursor()
cursor = database.cursor()
query = """INSERT INTO sanction (
id,
organization_type, organization, date,
decision_number, penalty_type, penalty_way,
penalty, violation, execution_period,
article, note, type_npa,
department, uploaded_date)
VALUES (
null,
%s, %s, STR_TO_DATE(%s,"%%d.%%m.%%Y"),
%s, %s, %s,
%s, %s, STR_TO_DATE(%s,"%%d.%%m.%%Y"),
%s, %s, %s,
%s, %s)"""
for r in range(1, sheet.nrows):
organization_type = sheet.cell(r,1).value
organization = sheet.cell(r,2).value
date = (sheet.cell(r,3).value)
decision_number = sheet.cell(r,4).value
penalty_type = sheet.cell(r,5).value
penalty_way = sheet.cell(r,6).value
penalty = sheet.cell(r,7).value
violation = sheet.cell(r,8).value
execution_period = sheet.cell(r,9).value
article =sheet.cell(r,10).value
note =sheet.cell(r,11).value
type_npa =sheet.cell(r,12).value
department =sheet.cell(r,13).value
uploaded_date =datetime.now().strftime("%Y-%m-%d %H:%M")
values = (organization_type, organization, date, decision_number, penalty_type,
penalty_way,penalty, violation, execution_period,article, note, type_npa, department,uploaded_date)
mycursor.execute(query, values)