Reputation: 65
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
Reputation: 65
df = pd.DataFrame(ph, columns = ['Date']) ph['Date'] = pd.to_datetime(df['Date''])
Upvotes: 1
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