我有CSV文件包含评论,我正在做一些NLP预处理(令牌化,阻止..etc)我在最终结果中只有一个问题。这是我的代码:
def clean_doc(r):
stop_free = " ".join([i for i in r.lower().split() if i not in stop])
punc_free = ''.join(ch for ch in stop_free if ch not in exclude)
normalized = " ".join(lemma.lemmatize(word) for word in punc_free.split())
stemmed = "".join([stemmer.stem(i) for i in normalized])
return stemmed
##----------------------------------------------------------------------
with open('test.csv', 'r') as csvfile:
data = csv.reader(csvfile, delimiter=',')
stemmer = PorterStemmer()
stop = set(stopwords.words('english'))
exclude = set(string.punctuation)
lemma = WordNetLemmatizer()
texts = []
next(data)
for row in data:
r = row[1]
texts.append(clean_doc(r))
print(texts)
变量(文本)不会打印任何内容。有谁能告诉我我哪里错了?...提前致谢