I have a simple csv in which there are a Date and Activity column like this:
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
Its seems that pandas change the day by the month or something like that:
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?
You could specify the date format in the pd.to_datetime parameters:
pd.to_datetime
dataset['Date'] = pd.to_datetime(dataset['Date'], format='%Y-%m-%d')
2.1m questions
2.1m answers
60 comments
57.0k users