plshelpimpoor
plshelpimpoor

Reputation: 65

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

import glob
import pandas as pd
import datetime

my_dates = ['Date']
sorted(my_dates, key=lambda x :datetime.datetime.strptime(x,'%m/%d/%Y'))

Getting the error in title. Not sure why. the date format in excel sheet is 1/2/2020 (m/d/yyyy) Tried many methods off google search and getting same error. Checked excel sheet to see if any dates written wrong but nope.

Python lists the column as object/list

Upvotes: 2

Views: 505

Answers (2)

plshelpimpoor
plshelpimpoor

Reputation: 65

df = pd.DataFrame(ph, columns = ['Date']) ph['Date'] = pd.to_datetime(df['Date''])

Upvotes: 1

frost-nzcr4
frost-nzcr4

Reputation: 1620

In the first loop you've got x = 'Date' which can't be parsed as date, but it will when my_dates = ['10/28/2020']

Upvotes: 0

Related Questions