I have a CSV file with two columns contains sentence. for example Test.csv:
Col[1]
----------------------
This trip was amazing.
Col[2]
--------------------
The cats are playing.
so I did some nlp process:
with codecs.open('test.csv','r', encoding='utf-8', errors='ignore') as myfile:
data = csv.reader(myfile, delimiter=',')
next(data)
stops = set(stopwords.words("english"))
stemmer = PorterStemmer()
for row in data:
word_tokens1 = word_tokenize(row[1].lower())
word_tokens2 = word_tokenize(row[2].lower())
remo1 = [w for w in word_tokens1 if w in re.sub("[^a-zA-Z]"," ",w )]
remo2 = [w for w in word_tokens2 if w in re.sub("[^a-zA-Z]"," ",w)]
list1 = [w for w in remo1 if not w in stops]
list2 = [w for w in remo2 if not w in stops]
for w in list1:
l = stemmer.stem(w)
print(l)
for w in list2:
l2 = stemmer.stem(w)
print(l2)
my problem is when I do stemming, and when I print it:
trip
amazi
cat
play
it print each word in a row. how can I return to the sentence after stemming like:
Col[1]:
-------------------
trip amazi
Col[2]:
-------------------
cat play