Reputation: 345
I have a data set includes restaurant reviews. I've processed my data and this is how my data set look like(0 and 1 shows is it positive or negative review):
0 ['wow', 'loved', 'place'] 1
1 ['crust', 'good'] 0
2 ['not', 'tasty', 'texture', 'nasty'] 0
3 ['stopped', 'late', 'may', 'bank', 'holiday', ... 1
4 ['the', 'selection', 'menu', 'great', 'prices'] 1
To be brief, i want to use PorterStemmer and this is how i studied to use it:
for i in range(1000):
for word in df['Review'][i]:
word = stemmer.stem(word)
I studied to use porterstemmer to stemming but it did not work. Any word did not stem(for example, in first data i expected the 'loved' word should become a 'love'). My data is still same with the dataframe which i shared above and i could not fix this.
Upvotes: 0
Views: 336
Reputation: 6826
Your code - which would be much easier to run/debug if it were a minimal reproducible example - is missing one line to replace the original word with the result of the stemming:
for i in range(1000):
for word in df['Review'][i]:
word = stemmer.stem(word)
df['Review'][i] = word ########## added
if you also add:
print( f"{word=}" )
the stemming output is:
word='wow'
word='love'
word='place'
word='crust'
word='good'
word='not'
word='tasti'
word='textur'
word='nasti'
word='stop'
word='late'
word='may'
word='bank'
word='holiday'
word='the'
word='select'
word='menu'
word='great'
word='price'
Next time you ask a question you should make the code a minimal reproducible example - this does two things: 1. getting your code to be minimal and confirming that the code you post still shows the same problem often helps to find/fix the problem, and 2) it's much easier for readers of your question to test for themselves. Never forget you're asking people to use their own time and effort to try help you with the only reward being at best a point or two of reputation; providing good runnable short code and a clear description of what's wrong with it will help you get an answer.
Upvotes: 1