我正在处理一个 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/