nltk stopwords -attributeError:' function'对象没有属性'单词'
这是我的导入:
from nltk.corpus import stopwords
这是我的代码:
def stopwords(text):
"""a function for removing the stopword"""
sw = stopwords.words('english')
# removing the stop words and lowercasing the selected words
text = [word.lower() for word in text.split() if word.lower() not in sw]
# joining the list of words with space separator
return " ".join(text)
应用:
df['col_text'] = df['col_text'].apply(stopwords)
我有一个错误: attributeError:'函数'对象没有属性'单词'
有人可以帮助我解决这个问题吗?
This is my import:
from nltk.corpus import stopwords
And this is my code:
def stopwords(text):
"""a function for removing the stopword"""
sw = stopwords.words('english')
# removing the stop words and lowercasing the selected words
text = [word.lower() for word in text.split() if word.lower() not in sw]
# joining the list of words with space separator
return " ".join(text)
Applying:
df['col_text'] = df['col_text'].apply(stopwords)
I got this error:
AttributeError: 'function' object has no attribute 'words'
Someone can help me with this problem please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您好,问题在于您将函数命名为nltk.corpus模块。您应该为您的功能找到另一个名称,我认为它会起作用。
Hello the problem is that you've named your function like the nltk.corpus module. You should find an other name for your function and it'll work I think.