繁体   English   中英

AttributeError: 'float' object has no attribute 'strip' (如何消除这个错误)

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

文本预处理

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'

当我尝试在 jupyter 中执行此代码时,显示以下错误,任何知道如何解决的人。 删除浮动或条带也会显示错误。

原来的 output 应该显示客户的评论。

该错误表明在您的笔记本中reviews.comment是一个list ,但它显然不仅包含字符串,还包含浮点数。 这会立即产生您看到的错误。

也许首先检查为什么你的review.comment中有浮动,并确保它有充分的理由并且没有错误。

此外,如果浮点数没问题,只需将其转换为字符串:

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.

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