0

I have a csv file which contains a date column, the dates in this file have the format of 'dd.mm.yy', when pandas parse the dates it understands the day as a month if it was less than or equal to 12, so 05.01.05 becomes 01/05/2005.

How can I solve this issue

Regards

ManKeer
  • 543
  • 2
  • 6
  • 27

1 Answers1

0

This is one way to solve it using pandas.to.datetime and setting the argument dayfirst=True. However, I've had to make assumptions about the format of your data since you are not sharing any code. In the case below the original format of the date column is object.

import pandas as pd

df = pd.DataFrame({
'date': ['01.02.20', '25.12.19', '10.03.18'],
})

df = pd.to_datetime(df['date'], dayfirst=True)

df

0   2020-02-01
1   2019-12-25
2   2018-03-10
Name: date, dtype: datetime64[ns]
CHRD
  • 1,917
  • 1
  • 15
  • 38