I have one data frame which has two date colums. but the dates are in string datatype. I am trying to convert them into panda datetime format to substract from each other. but i am getting the error. Can i get some help?
df1 = pd.DataFrame({‘date1′ : [’30-May-2024′,’30-May-2024′,’30-May-2024′],’date2′ : [’20-May-2024′,’20-May-2024′,’10-May-2024’]})
result date1-date2 :
10 10 20
I tried doing following but it is giving me error.
pd.to_datetime((df1[‘date1’])).date() – pd.to_datetime((df1[‘date2’])).date()
ERROR: time data “30-May-2024” doesn’t match format “%d-%B-%Y”, at position 1.