import csv
from datetime import datetime
file = open('RTWR.csv', newline ='')
routed = csv.reader(file)
header = next(routed) #header
data = []
for row in routed:
#row = ['PostDate', 'RouteID', 'DriverID', 'Name', 'Address', 'City', 'State', 'Zip','CustID','CompletedTime','ArrivalTime']
Post_Date = datetime.strptime(row[0], '%m/%d/%Y') # converting the rows to their approriate data types for simpler parsing later
Route_ID = str(row[1])
Driver_ID = str(row[2])
Name = str(row[3])
Address = str(row[4])
City = str(row[5])
State = str(row[6])
Zip = str(row[7])
Cust_ID = str(row[8])
Completed_time = datetime.strptime(row[9], '%m/%d/%Y %H:%M:%S %p')
''' Ct = datetime.strptime(Completed_time, "%m/%d/%Y %H:%M:%S %p") #tried creating a new variable same issue '''
Arrival_time = str(row[10])
data.append([Post_Date,Route_ID,Driver_ID,Name,Address,City,State,Zip,Cust_ID,Arrival_time,Completed_time])
Completed_time的值看起来像这样---> 11/17/2019 5:46:48 PM
我不断在下面收到以下错误:
raise ValueError("time data %r does not match format %r" %
ValueError: time data '' does not match format '%m/%d/%Y %H:%M:%S %p'
是我使用的格式错误,非常感谢您的帮助。