My code is correct, error still shows up

Hi All!

I am sure that my code is correct, but why the error still shows up? thank you!!
Screen Link:

My Code:

# Extract the years and convert them to a float type
dete_resignations['cease_date'] = dete_resignations['cease_date'].str.split('/').str[-1]
dete_resignations['cease_date'] = dete_resignations['cease_date'].astype("float")

# Check the values again and look for outliers

What I expected to happen:

What actually happened:

AttributeError: Can only use .str accessor with string values, which use np.object_ dtype in pandas

Looks like the data in that column are not strings but int or float. You can use dete_resignations[‘cease_date’].dtype to see the type of the data

1 Like

Mostly agree with @alegiraldo666. Sometimes it happens to me when I run the same code cell twice: on the first run you convert the data, then you add some changes to the code and run it again it’s when similar errors arise. Might have happen something similar to you!