python - 从文本 block 中删除停用词

标签 python textblob

我正在处理一个 textblob,其中一个步骤是去除停用词。 Textblob 是不可变的,所以我将其中一个变成了一个列表来完成这项工作:

blob = tb(tekst)
lista = [word for word in blob.words if word not in stopwords.words('english')]
tekst = ' '.join(lista)
blob = tb(tekst)

这个问题有更简单/更优雅的解决方案吗?

最佳答案

你可以试试这个代码:

from textblob import TextBlob
from nltk.corpus import stopwords

b="Do not purchase these earphones. It will automatically disconnect and reconnect. Worst product to buy."
text=TextBlob(b)

# Tokens
tokens=set(text.words)
print("Tokens: ",tokens)
# stopwords
stop=set(stopwords.words("english"))

# Removing stop words using set difference operation
print("Filtered Tokens: ",tokens-stop)
输出:
* 代币: {'buy', 'disconnect', 'will', 'to', 'purchase', 'reconnect', 'product', 'It', 'Do', 'and', 'Worst', 'earphones', '不是','自动','这些'}
过滤的 token : {'buy', 'disconnect', 'purchase', 'reconnect', 'product', 'It', 'Do', 'Worst', 'earphones', 'automatically'}*

关于python - 从文本 block 中删除停用词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46959492/

相关文章:

python - 为什么 Tkinter 几何需要字符串?

python-2.7 - TEXTBLOB 计算的极性分数背后的逻辑?

python - 在 Pyspark-Cluster 模式下的工作节点上安装外部库

python - 使用条件删除列表的元素

python - 在 mac 中将 MySQL Workbench 与 Eclipse 中的 Django 连接

python - Numpy - 一维和二维数组的不同行为

python - 操作系统错误 : [Errno 9] Bad file descriptor

python - 如果某些行的列中的值丢失,如何应用 TextBlob?

python - 在数据帧的新列中返回 TextBlob 正、负或中性分类