Home > database >  AttributeError: 'float' object has no attribute 'strip' (how to remove this erro
AttributeError: 'float' object has no attribute 'strip' (how to remove this erro

Time:01-24

TEXT PREPROCESSING

reviews=[comment.strip() for comment in reviews.comment] # remove both the leading and the trailing characters
reviews=[comment for comment in reviews if comment] # removes empty strings, because they are considered in Python as False
reviews[0:10]

OUTPUT :

AttributeError: 'float' object has no attribute 'strip'

when i am trying to execute this code in jupyter below error is showing , anyone who knws how to solve. removing the float or strip also shows error.

the original output should show the reviews by customers.

CodePudding user response:

The error indicates that in your notebook reviews.comment is a list, but it apparently contains not only strings but also floats. This immediately produces the error you see.

Maybe first check why there is a float in your review.comment and make sure it is there for a good reason and not already in error.

Furthermore, if the float is OK just convert it to a string:

reviews=[str(comment).strip() for comment in reviews.comment] # remove both the leading and the trailing characters
  • Related