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

Viewed 7582

My columns with dates have this format 7/5/17 14:44. When I convert the column from an object to date format my dates are coming out 17-5-7 which is not what I want. I just want to have 7/5/17.

When I am try to switch the order in my date format with format='%d/%m/%Y' I get the following error:

ValueError: time data '3/20/12 0:00' does not match format '%d/%m/%Y' (match)

My code is below. Where am I going wrong? Also, since I have 3 columns I need to format, is there a more efficient way to do this?

name_cols = ['GUID1', 'GUID2', 'Org ID', 'Org Name', 'Org Type', 'Chapter', 'Join Date', 'Effective Date', 'Expire Date']
pull_cols = ['Org ID', 'Org Name', 'Org Type', 'Chapter', 'Join Date', 'Effective Date','Expire Date']
df1 = pd.read_csv(path, header=None, encoding="ISO-8859-1", names=name_cols, usecols=pull_cols, index_col=False)
df1['Join Date'] = pd.to_datetime(df1['Join Date'], format='%d/%m/%Y')
df1['Effective Date'] = pd.to_datetime(df1['Effective Date'])
df1['Expire Date'] = pd.to_datetime(df1['Expire Date'])
1 Answers
Related