python清洗数据去除停用词_Python从pandas数据帧中删除停用词
我想從我的專(zhuān)欄“tweets”中刪除停用詞.如何迭代每一行和每個(gè)項(xiàng)目?
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]
標(biāo)簽:python,pandas
來(lái)源: https://codeday.me/bug/20190926/1821562.html
超強(qiáng)干貨來(lái)襲 云風(fēng)專(zhuān)訪(fǎng):近40年碼齡,通宵達(dá)旦的技術(shù)人生總結(jié)
以上是生活随笔為你收集整理的python清洗数据去除停用词_Python从pandas数据帧中删除停用词的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
 
                            
                        - 上一篇: elasticsearch 客户端工具_
- 下一篇: python函数调用键盘热键_Tkint
