Attribute error using Python - Python Help - Discussions on Python.org
Attribute error using Python Python Help Tabhrez123 (Tabhrez) January 24, 2024, 2:34pm 1 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. image 833×571 35.4 KB bryevdv (Bryan Van de Ven) January 24, 2024, 4:26pm 2 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. c-rob (Chuck R.) January 25, 2024, 12:34pm 3 Please post all of the code as text, not an image, so someone can step through it. Tabhrez123 (Tabhrez) January 25, 2024, 3:55pm 4 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! bryevdv (Bryan Van de Ven) January 25, 2024, 5:28pm 5 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.
Tabhrez123 (Tabhrez) January 26, 2024, 4:44pm 6 Thats fine. Thanks for explaining. I have now sorted the issue.