简体   繁体   中英

AttributeError: 'float' object has no attribute 'strip' (how to remove this error)

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM