Andres Silvia
Andres Silvia

Reputation: 59

Python - ValueError: unconverted data remains: 09

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])

error: enter image description here

csv file: enter image description here

Upvotes: 1

Views: 961

Answers (1)

Rakesh
Rakesh

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

Related Questions