Skip to content
Advertisement

Error: ‘str’ object has no attribute ‘shape’ while trying to covert datetime in a dataframe

Consider a I have a column called ‘test’ of a dataframe. The column elements are like this:

JavaScript

I want to make the each column elements of the dataframe as 2016-04-01. Based on this I have written a code which is working fine in spyder but when I am trying to apply it to Jupyter Notebook it is showing some error AttributeError: ‘str’ object has no attribute ‘shape’

My code is:

JavaScript

Initially I have used the following code

JavaScript

In both cases it is showing error. Kindly help so that I can use it in Jupyter Notebook.

Note that dtypes is object for ‘test’.

Advertisement

Answer

We need to use format param while converting the str to datetime

Input

JavaScript

Input df

JavaScript

Code

JavaScript

Output

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