Rajat Jain
Rajat Jain

Reputation: 41

datetime throwing value error in python

I am trying to convert datetime format of a column in dataframe in python original date - 16-Jul-2018 00:00 final date- 2018-08-16 00:00

results['Date1']=dt.datetime.strptime(str(results['Date']), "%d-%b-%Y %H:%M").strftime("%Y-%m-%d %H:%M")

but it is giving me value error. When trying specific string in syntex, it works enter image description here

Upvotes: 2

Views: 108

Answers (1)

Joe
Joe

Reputation: 12417

This should work:

result['Date1'] = pd.to_datetime(result['Date1'], format="%d-%b-%Y %H:%M").dt.strftime('%Y-%m-%d %H:%M')

Input:

               Date1
0  16-Jul-2018 00:00

Output:

              Date1
0  2018-07-16 00:00

Upvotes: 2

Related Questions