如何解决AttributeError:“ NoneType”对象没有属性“ lower
我试图在标签数据上实现CountVectorizer,但是每次它抛出属性错误时,都尝试了一切,但仍然无法理解为什么会出现此错误。这是我的代码,
vectorizer = CountVectorizer(tokenizer = lambda x: x.split(" "))
tag_dtm = vectorizer.fit_transform(tag_data['Tags'])
这是我得到的错误:
`AttributeError
Traceback (most recent call last)
<ipython-input-53-7a05ab3b6655> in <module>()
7 # and learns the vocabulary; second,it transforms our training data
8 # into feature vectors. The input to fit_transform should be a list of strings.
----> 9 tag_dtm = vectorizer.fit_transform(tag_data['Tags'])
3 frames
/usr/local/lib/python3.6/dist-packages/sklearn/feature_extraction/text.py in _preprocess(doc,accent_function,lower)
66 """
67 if lower:
---> 68 doc = doc.lower()
69 if accent_function is not None:
70 doc = accent_function(doc)
AttributeError: 'NoneType' object has no attribute 'lower'`
解决方法
'doc'中不包含任何数据/字符串,它是None类型。 None不是none或blank的含义,它是一种类型。 并使用“如果doc为None:”的条件进行检查。
,尝试将其转换为字符串,因为较低的是字符串函数,并且由于传递到CountVectorizer的数据之一是NoneType,因此实际上就钩在那里了
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。