[英]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: 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.
当我尝试在 jupyter 中执行此代码时,显示以下错误,任何知道如何解决的人。 removing the float or strip also shows error.
删除浮动或条带也会显示错误。
the original output should show the reviews by customers.原来的 output 应该显示客户的评论。
The error indicates that in your notebook reviews.comment
is a list
, but it apparently contains not only strings but also floats.该错误表明在您的笔记本中
reviews.comment
是一个list
,但它显然不仅包含字符串,还包含浮点数。 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.也许首先检查为什么你的
review.comment
中有浮动,并确保它有充分的理由并且没有错误。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.