I wish to convert a string in pandas to datetime, but conversion fails.
My data has the format for example 06.12.2015 This means day.month.year
try:
#Code that may raise an error
df['date']= pd.to_datetime(df['date'], format='%d%m%Y')
#Raising your own errors
raise Exception("Error converting date")
except Exception as e:
#code to run if error occurs
logging.error("Exception occurred " + filename , exc_info=True)
#code to run if error is raised
print("Conversion not work.")
else:
df['date']= pd.to_datetime(df['date'], format='%d.%m.%y')
then
print(df.dtypes)
gives object and exception is raised.
Can someone help me please?