2

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

0

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.