我最近在使用python在nlp中做项目。我需要预先处理一个csv文件,其中包含许多行和列的文本。我可以只能干掉简单的句子。并且无法立即阻止整个csv文件。我怎样才能做到这一点??在尝试阻止简单的csv文件时,我得到了错误
import csv
from nltk import PorterStemmer
port = PorterStemmer()
with open('status.csv', 'rb') as f:
reader = csv.reader(f)
for row in reader:
print(port.stem(row))
答案 0 :(得分:0)
因此,您需要执行几个步骤。
#Part 1
>>> import nltk
>>> from nltk import PorterStemmer
>>> test = 'this sentence is just a tester set of words'
>>> test_tokenize = nltk.word_tokenize(test)
>>> test_tokenize
['this', 'sentence', 'is', 'just', 'a', 'tester', 'set', 'of', 'words']
>>> port = PorterStemmer()
>>> for word in test_tokenize:
... print port.stem(word)
...
thi
sentenc
is
just
a
tester
set
of
word
#Part 2
with open('status.csv', 'rb') as f:
reader = csv.reader(f)
for row in reader:
#reference the column where the text is located
#text = row[column_index_for_text]
#then just complete the steps in part 1 to get the stemmed words