我的数据集第4列中的日期为1515,有没有办法绕过此错误?
cols[4] = cols[4] and cols[4].strftime("%d/%m/%Y") or ""
ValueError: year=1515 is before 1900; the datetime strftime() methods require year >= 1900
以下是确切的代码:
cursor.execute(SQL)
filename = r"C:\Projects\OPEN_KCI3.csv"
with open(filename, "wb") as fout:
writer = csv.writer(fout)
#writer.writerow([i[0] for i in cursor.description ]) # heading row
for row in cursor.fetchall():
cols = list(row)
cols[3] = cols[3] and cols[3].strftime("%d/%m/%Y") or ""
cols[4] = cols[4] and cols[4].strftime("%d/%m/%Y") or ""
writer.writerow(cols)
cursor.close()
connection.close()