Skip to content
Advertisement

AttributeError: Can only use .dt accessor with datetimelike values

Hi I am using pandas to convert a column to month. When I read my data they are objects:

JavaScript

So I am first making them to date time and then try to make them as months:

JavaScript

Also if that helps:

JavaScript

So, the error I get is like this:

JavaScript

EDITED:

Date columns are like this:

JavaScript

Do you have any ideas? Thank you very much!

Advertisement

Answer

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.

JavaScript

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

See the docs

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement