【发布时间】:2023-01-23 17:40:09
【问题描述】:
文本预处理
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]
输出 :
AttributeError: 'float' object has no attribute 'strip'
当我尝试在 jupyter 中执行此代码时,显示以下错误,任何知道如何解决的人。删除浮动或条带也会显示错误。
原始输出应显示客户的评论。
【问题讨论】:
-
好吧,在不知道评论内容是什么的情况下,您可以将其强制为字符串,如下所示:
str(comment).strip() -
解决此问题的方法是限制使用条()字符串对象
标签: python dataframe jupyter css-float variable-assignment