Explore Courses Blog Tutorials Interview Questions
0 votes
in Data Science by (17.6k points)

I want to remove the stop words from my column "tweets". How do I iterative over each row and each item?

pos_tweets = [('I love this car', 'positive'),

    ('This view is amazing', 'positive'),

    ('I feel great this morning', 'positive'),

    ('I am so excited about the concert', 'positive'),

    ('He is my best friend', 'positive')]

test = pd.DataFrame(pos_tweets)

test.columns = ["tweet","class"]

test["tweet"] = test["tweet"].str.lower().str.split()

from nltk.corpus import stopwords

stop = stopwords.words('english')

1 Answer

0 votes
by (41.4k points)

Using List Comprehension

test['tweet'].apply(lambda x: [item for item in x if item not in stop])


0               [love, car]

1           [view, amazing]

2    [feel, great, morning]

3        [excited, concert]

4            [best, friend]

If you wish to learn more about Pandas visit this Pandas Tutorial.

If you are interested to learn Python from Industry experts, you can sign up for this Python Certification Course by Intellipaat.

Related questions

Browse Categories