python - 如何使用 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', ':', '(']
解决方案
推荐阅读
- ios - SnapChat 如何在标签之间如此快速地切换?
- swift - Swift 代码问题!=
- python - 仅将文本附加到非空值 pandas Dataframe
- ssms - 从 SSMS 处理 Azure 分析服务器模型时出错
- python - nltk : 根据 POS 用其他词替换标记
- vim - Vim 拆分函数参数
- php - PHP 的 MySQL 数据库迁移 UTF-8 问题
- tensorflow - 是否可以训练 Tensorflow 来检测物体上的缺陷?
- c# - 如何使用 Selenium c# 将剪贴板中的 url 粘贴到 Chrome 中的地址栏?
- javascript - 反应最佳实践:将状态传递给孩子还是让孩子直接检查状态?