I have a dataframe which looks like this:
Date ID Product
01/10/2018 01 XM0
01/10/2018 02 XM0
02/10/2018 02 BY2
The date is currently being recognised as an object so I run the following code to convert to datetime:
df['Date'] = pd.to_datetime(df['Date'])
For some reason when I run this line of code the output shows that the month of the date has been changed to January when it should be October:
Date ID Product
2018-01-10 01 XM0
2018-01-10 02 XM0
2018-02-10 02 BY2
Is there a way to prevent this so that the dates are accurately converted into the actual date when I run the datetime conversion line?
Thank you :)
Use dayfirst=True
Ex:
df["Date"] = pd.to_datetime(df["Date"], dayfirst=True)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With