我想从“ tweets”列中删除停用词。如何遍历每一行和每一项目?
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')
使用列表理解
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]