简体   繁体   English

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

[英]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.

相关问题 AttributeError: 'float' object 没有属性 'strip' - AttributeError: 'float' object has no attribute 'strip' 'float'对象没有属性'strip' - 'float' object has no attribute 'strip' 'float' 对象没有属性 'strip'? - 'float' object has no attribute 'strip'? 我不断收到错误:AttributeError: 'NoneType' object has no attribute 'strip' - I keep getting the error: AttributeError: 'NoneType' object has no attribute 'strip' 如何修复 AttributeError: 'NoneType' object has no attribute 'strip' in this specific code? - how to fix AttributeError: 'NoneType' object has no attribute 'strip' in this specific code? AttributeError: 'NoneType' object has no attribute 'strip' 如何解决? - AttributeError: 'NoneType' object has no attribute 'strip' how to solve? 我该如何解决这个问题:AttributeError: 'NoneType' object has no attribute 'strip - How can i fix this :AttributeError: 'NoneType' object has no attribute 'strip AttributeError:'list'对象没有属性'strip' - AttributeError: 'list' object has no attribute 'strip' Python 2: AttributeError: 'file' 对象没有属性 'strip' - Python 2: AttributeError: 'file' object has no attribute 'strip' Python 2:AttributeError:“list”对象没有“strip”属性 - Python 2: AttributeError: 'list' object has no attribute 'strip'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM