1

An example of a value in the Date column:

19/08/2017

Previously, I tried:

dividends['Date'] = pd.to_datetime(dividends['Date'])

to convert my column to have a datetime date type. However, when I then created charts out of this dataset (with 'Date' having a datetime date type), it always looked odd:

enter image description here

Having done a bit of trouble shooting online, I think the reason is because of the formatting of my datetime conversion. However, when I try to use this:

dividends['Date'] = pd.to_datetime(dividends['Date'],format='%d-%m-%y')

I get the error message

ValueError: time data '19/08/2017' does not match format '%d-%m-%y' (match)

Why is this, and how do I fix it? Cheers.

1
  • Change format to '%d/%m/%Y'. Does it work now? Commented May 25, 2020 at 23:40

1 Answer 1

1

Use the following code:(note that I used Y in format):

dividends['Date'] = pd.to_datetime(dividends['Date'],format='%d-%m-%Y')

You could also use the following format:

'%d/%m/%Y'

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.