Reputation: 59
i'm working on two csv files that contain date column, the first csv file worked fine with my codes but i got error on the second file showing as " ValueError: unconverted data remains: 09".
see below for my codes and screenshots, can anyone help me??
codes:
with open(source_csv,newline="") as csvfile:
csvreader = csv.reader(csvfile, delimiter=',', quotechar='|')
next(csvreader, None) # skip the headers
for row in csvreader:
dictList.append([datetime.strptime(row[0],'%b-%d').strftime('%m%d%Y'),row[1], row[0]])
mmyy = row[0].split("-")
month.append(str(mmyy[0]))
total += int(row[1])
Upvotes: 1
Views: 961
Reputation: 82785
Looks like 09
represents the year and not the month.
import datetime
s = "Jan-09"
print(datetime.datetime.strptime(s, '%b-%y').strftime('%m-%d-%Y'))
Output:
01-01-2009
Upvotes: 1