Issue
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')
Solution
Using List Comprehension
test['tweet'].apply(lambda x: [item for item in x if item not in stop])
Returns:
0 [love, car]
1 [view, amazing]
2 [feel, great, morning]
3 [excited, concert]
4 [best, friend]
Answered By - Liam Foley
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.