Python ValueError: time data '' does not match format '%m/%d/%Y'

Python ValueError: time data '' does not match format '%m/%d/%Y'

我有以下错误:

line 73, in formatFile outRow.append(datetime.datetime.strptime(row[5],'%m/%d/%Y').strftime('%Y-%m-%d')) ValueError: time data '' does not match format '%m/%d/%Y'

脚本如下:

import datetime

  def formatFile(fname):
    print(fname)

       formattedFile=open(workingFolder() + '\FormattedFile.csv','w')
       writer = csv.writer(formattedFile, delimiter=',', quotechar='"', quoting=csv.QUOTE_ALL,lineterminator='\n')
       writer.writerow(["Name","Unit","Unit Size","Other","Note","Mode Here"])

       with open(fName) as f:
          reader=csv.reader(f,delimiter=',')    
          next(reader)
          for row in reader:
              outRow=[]


              outRow.append(datetime.datetime.strptime(row[5],'%m/%d/%Y').strftime('%Y-%m-%d'))

              #other script here that works well as part of a for loop

              print(outRow)
              writer.writerow(outRow)

我的日期在 .csv 文件中,文本如下所示:“11/19/2017” 我想要这种格式:“2017-11-19”。不确定我做错了什么?

我已经阅读了大约 5 遍,但仍然不确定为什么它会给我错误: https://docs.python.org/2/library/datetime.html

此处为 csv 文件示例:

"Name","Unit","Unit Size","Other","Mode","Date" 
"name here","unit here","YYY x YY","Note","Mode here","11/19/2017"
"name here","unit here","YYY x YY","Note","Mode here","11/20/2017"
"name here","unit here","YYY x YY","Note","Mode here","12/04/2017"

列表底部的总行导致文件崩溃...已更正:

for row in reader:
    if "Total" not in row:
       #script here
    else:
        break