【问题标题】:AttributeError: 'float' object has no attribute 'split' in pandasAttributeError:'float' 对象在 pandas 中没有属性 'split'
【发布时间】:2019-07-19 09:36:18
【问题描述】:

我想计算每行的标签数,但是在遍历每一行时,我得到属性错误,即使我的列数据类型是对象。请看下面的代码。

Tag_data.dtypes
Id            int64

标题对象 身体对象 标签对象 dup_count int64 数据类型:对象

actual code 
Tag_data["tag_counts"]=Tag_data["Tags"].apply(lambda  text:len(text.split(" ")))
Tag_data.head()

AttributeError: 'float' 对象没有属性 'split'

【问题讨论】:

  • Tag_data.dtypes Id int64,表示Tag_data只有一列Id
  • 我没有正确粘贴:这里有一个正确的:Id int64 Title object Body object Tags object dup_count int64 dtype: object

标签: python pandas python-2.7 data-science


【解决方案1】:

“标签”列的数据类型似乎是浮点数。 在应用拆分功能之前尝试将其更改为字符串:Tag_data['Tags'].apply(str)

【讨论】:

    猜你喜欢
    • 2017-07-02
    • 2016-07-25
    • 2018-03-14
    • 1970-01-01
    • 2021-04-05
    • 2016-01-31
    • 2016-09-19
    • 2020-09-14
    • 2021-07-25
    相关资源
    最近更新 更多