首页 > 解决方案 > 如何使用 python 对 csv 文件中的多行文本应用标记化和停用词

问题描述

我有一个 csv 文件,其中包含一列多行句子。我需要使用 python 从每一行文本中标记、识别和删除停用词。我可以一次做一行文本,但你如何使用 python 让它读取每一行并应用标记化和停用词?这就是我的一句话代码:

from nltk.tokenize import word_tokenize
covid_text = "i think i need to self isolate because i don't feel good :("
stop_words = set(stopwords.words('english')) 
word_tokens = word_tokenize(covid_text) 
filtered_sentence = [w for w in word_tokens if not w in stop_words] 
filtered_sentence = [] 
for w in word_tokens: 
    if w not in stop_words: 
        filtered_sentence.append(w) 

print(word_tokens) 
print(filtered_sentence)```

Output:
['i', 'think', 'i', 'need', 'to', 'self', 'isolate', 'because', 'i', 'do', "n't", 'feel', 'good', ':', '(']
['think', 'need', 'self', 'isolate', "n't", 'feel', 'good', ':', '(']


标签: pythoncsvtokenizemultipleselection

解决方案


推荐阅读