Bad datetime conversion in pandas when a csv file it's opened

Viewed 180

I have a simple csv in which there are a Date and Activity column like this: enter image description here

and when I open it with pandas and I try to convert the Date column with pd.to_datetime its change the date. When there are a change of month like this

enter image description here

Its seems that pandas change the day by the month or something like that:

enter image description here

The format of date that I want it's dd-mm-yyyy or yyyy-mm-dd.

This it's the code that I using:

import pandas as pd
dataset = pd.read_csv(directory + "Time 2020 (Activities).csv", sep = ";")
dataset[["Date"]] = dataset[["Date"]].apply(pd.to_datetime)

How can I fix that?

1 Answers

You could specify the date format in the pd.to_datetime parameters:

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