【发布时间】:2020-05-25 03:18:54
【问题描述】:
我正在尝试从我拥有的标记列表中删除停用词。但是,似乎这些词没有被删除。会有什么问题?谢谢。
试过了:
Trans = []
with open('data.txt', 'r') as myfile:
file = myfile.read()
#start readin from the start of the charecter
myfile.seek(0)
for row in myfile:
split = row.split()
Trans.append(split)
myfile.close()
stop_words = list(get_stop_words('en'))
nltk_words = list(stopwords.words('english'))
stop_words.extend(nltk_words)
output = [w for w in Trans if not w in stop_words]
Input:
[['Apparent',
'magnitude',
'is',
'a',
'measure',
'of',
'the',
'brightness',
'of',
'a',
'star',
'or',
'other']]
output:
It returns the same words as input.
【问题讨论】:
-
这可能与您输入的双括号有关。
Trans的第一个也是唯一的元素是一个单词列表,因此列表理解中的条件通过了。
标签: python nlp stop-words