python - TypeError:“float”类型的对象没有 len() - NLP
问题描述
我正在尝试创建一个具有文本长度的变量。我正在使用下面的代码:
messages['length']=messages['Review Text'].apply(len)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-24-fa1723bfb3a3> in <module>
----> 1 messages['length']=messages['Review Text'].apply(len)
~\anaconda3\lib\site-packages\pandas\core\series.py in apply(self, func, convert_dtype, args, **kwds)
4136 else:
4137 values = self.astype(object)._values
-> 4138 mapped = lib.map_infer(values, f, convert=convert_dtype)
4139
4140 if len(mapped) and isinstance(mapped[0], Series):
pandas\_libs\lib.pyx in pandas._libs.lib.map_infer()
TypeError: object of type 'float' has no len()
我应该怎么做才能解决这个问题?
解决方案
仔细检查您的数据。该消息"TypeError: object of type 'float' has no len()"
使我相信您的至少一个单元格'Review Text'
不是文本值,而是浮点值。
推荐阅读
- fortran - gfortran-4.9(和更新版本)中的错误?
- php - 如何使用 DB Facades 访问数据库?
- matlab - 在已排序文件的文件夹中查找特定文件
- ruby-on-rails - 在日历中垂直返回同一工作日 - Ruby on Rails
- r - 在 R 中编写函数时,我应该何时使用自己的错误消息?
- javascript - 在 ngFor 中隐藏/显示单个或特定按钮
- python - 如何通过使用 bash 脚本传递参数来运行 python 文件?
- java - JxBrowser 更新浏览器
- javascript - Javascript 表单的意外行为
- java - 如何使用java将对象相互链接