I have dataframe in pandas that has two dates columns:
>>>ID name start end
0 12 Tik 1/6/2020 None
1 32 Tak 12/31/2019 None
2 45 Tek 9/1/2019 1/30/2020
3 78 Tok 9/1/2019 1/29/2020
I'm trying to convert those dates into datetime to be in format of Y-m-d e.g that 12/31/2019 will be 2019-12-31 :
df[['start','end']] =df[['start','end']].apply(pd.to_datetime, format=''%Y-%m-%d'')
but whenever I run this I get error:
ValueError: time data 1/6/2020 doesn't match format specified
I have tried than to specify the format to be like the given date (e.g (d-m-Y):
df[['start','end']] =df[['start','end']].apply(pd.to_datetime, format=''%d-%m-%Y'')
>>>ValueError: time data '1/6/2020' does not match format '%d-%m-%Y' (match)
I have tried to break it as suggest in the first answer here: How to change the datetime format in pandas and to first conver to datetime and then use strftime but in the first line I got the error that Ineed to specify the format.
I can't find any reason why is this happen, maybe is because the day and month do not have two digits?
my end goal is to convert those date columns into %Y-%m-%d format