AttributeError: Can only use .dt accessor with datetimelike values

The Solution to AttributeError: Can only use .dt accessor with datetimelike values is


Your problem here is that to_datetime silently failed so the dtype remained as str/object, if you set param errors='coerce' then if the conversion fails for any particular string then those rows are set to NaT.

df['Date'] = pd.to_datetime(df['Date'], errors='coerce')

So you need to find out what is wrong with those specific row values.

See the docs

~ Answered on 2015-10-27 12:28:06


Most Viewed Questions: