nltk stopwords -attributeError:' function'对象没有属性'单词'

发布于 2025-02-11 06:45:21 字数 567 浏览 1 评论 0原文

这是我的导入:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

执手闯天涯 2025-02-18 06:45:22

您好,问题在于您将函数命名为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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文