0

<html>
            <body>
            <table border=1>
            <tr>
            <th>label</th>
            <th>rev</th>
            </tr>
            <tr>
            <td>0</td>
            <td>[ story man unnatural feelings pig...] </td>
            </tr>
            <tr>
            <td>0</td>
            <td>[ airport starts brand new luxury ...] </td></tr>
            <tr>
            <td>0</td>
            <td>[ film lacked something couldnt pu...] </td></tr>
            <tr>
            <td>0</td>
            <td>[ sorry everyone know supposed art...] </td></tr>
            <tr>
            <td>0</td>
            <td>[ little parents took along theate..]</td></tr>
            </table>
            </body>
            </html>

IMAGE-> [1]: https://i.stack.imgur.com/j2EAK.jpg

My dataframe looks like above, I tried the below code to stem it :

from nltk.stem.porter import PorterStemmer
ps=PorterStemmer()
da.rev=[ps.stem(word) for word in da.loc[:,'rev']]

but it was resulting in the same data frame again, can't point out what went wrong. Any help will be dearly appreciated. Thank you for your time

2
  • Please share a sample of your data rather than a screenshot, it makes it much easier to reproduce! Jan 13, 2019 at 8:49
  • Please excuse me for the noobish response I'm new . I hope the dataframe in the snippet helps
    – lipi sahu
    Jan 13, 2019 at 11:47

1 Answer 1

0

Hard to say without seeing your exact code but if each item in the series is a list of strings you could try

da.rev.apply(lambda x: [ps.stem(word) for word in x])

8
  • [ story man unnatural feelings pig] got changed to [, , s, t, o, r, y, , , , , m, a, n, , ...] The words didn't stem too
    – lipi sahu
    Jan 13, 2019 at 18:30
  • Try da.rev.apply(lambda x: [ps.stem(word) for word in x.split()]) Jan 13, 2019 at 21:05
  • That worked, thanks a lot! Should it work similarly for lemmatization?
    – lipi sahu
    Jan 14, 2019 at 7:02
  • Yes, should be the same principle - something like from nltk.stem import WordNetLemmatizer, lem = WordNetLemmatizer(), da.rev.apply(lambda x: [lem.lemmatize(word) for word in x.split()]) Jan 14, 2019 at 7:51
  • It gives me the same original dataframe without lemmatizing
    – lipi sahu
    Jan 14, 2019 at 8:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.