train_data = ["Consultant, changing, Waiting"]
I'm trying to apply the stemmer to the data with the following code, but It keeps the original data:
stemmer = stem.porter.PorterStemmer()
train_data = train_stemmer
for i in range(len(train_stemmer)):
train_stemmer[i] = stemmer.stem(train_stemmer[i])
The code runs fine but does not produce my expected result, which is:
["Consult, change, Wait"]
Two things jump out:
train_data
in your question is a list containing one string["Consult, change, Wait"]
, rather than a list of three strings["Consult", "change", "Wait"]
If you intended for the list to contain one string, this should work fine:
If you wanted a list of three strings, then modify to include quotes between commas:
Handling the upper vs. lowercase at the start of the word requires passing a parameter, but can make sense if you're trying to handle proper nouns (e.g. distinguish stemmed
change
from the nameChang
).Expected output when all three run: