date type: cannot convert unique date(object) to date type

36 Views Asked by At

date type of original Dataflame is object type. "23/07/01" means Year 2023, month 7, date 1

"23/07/01" is on 'data' column so I write code as below.

df['date'] = pd.to_datetime(df1['date'], format='%Y/%m/%d')

However the error below pops up ValueError: time data "23/07/03" at position 0 doesn't match format specified

1

There are 1 best solutions below

0
Mads Hougesen On

%Y means year with century. You need to use %y. See the documentation on strftime for more information.

Using the format "%y/%m/%d" should give the output you expect.

d = pd.to_datetime("23/07/01", format="%y/%m/%d")
print(d) # Timestamp('2023-07-01 00:00:00'