Attribute error using Python

Hi All,

I hope this message finds you well. I have encountered an error when coding a clean instruction on the data. Please see the image below for your reference. Would anyone please kindly advise the necessary alterations to resolve the error?

Thank you in advance.

Pease don’t post screenshots of code and error messages. Screenshots are inaccessible to screen readers and also make it impossible for anyone who wants to help to easily copy and paste any content they might want to try out for themselves. Just copy and paste (formatted) text instead.

You clean_text function expects all inputs to be strings, but you are applying it to a Pandas DataFrame column that contains floating point values. That is the source of the error. It’s not possible to offer any further guidance since that would depend on what you are actually trying to accomplish. Maybe it would make sense to convert the column to strings first and then “clean” it (probably not, but you never know). Or it’s entirely possible you just don’t need to do this step at all since “cleaning text” is not applicable to numbers.


Please post all of the code as text, not an image, so someone can step through it.

Dear Bryan,

Many thanks for your comments. I am new to this platform therefore was unsure regarding the format of the question, however thank you for explaining. I have zoomed into the issue at hand and I believe there is an issue with the data being proposed for text cleaning due to float numbers being present. This code actually came from an online tutorial so I was unsure regarding the error. The data as it stands seems to be extracted from SMS text messages which I have attempted to clean. Would there be a code to add to the programme that could skip floats in the cleaning process? I look forwards to your reply and thank you for your help!

There are lots of ways to remove values from lists, arrays, sequences. Which one is best depends on the specific circumstance. Please read about providing a complete Minimal, Reproducible Example that will help others help you.

Thats fine. Thanks for explaining. I have now sorted the issue.