码迷,mamicode.com
首页 > 其他好文 > 详细

去停用词

时间:2019-09-21 16:49:31      阅读:79      评论:0      收藏:0      [点我收藏+]

标签:txt   strip   readlines   python   and   word   return   coding   ext   

import pandas as pd
stop_words = []
with open('data/stop_words.txt','r',encoding='utf-8') as f:
    lines = f.readlines()
    for i in lines:
        word = i.strip()
        stop_words.append(word)
print(stop_words[:10])


def clean_stopwords(text,stop_words):
    data = []
    for sentence in text:
        data.append([ word for word in sentence if word not in stop_words])
    return data

去停用词

标签:txt   strip   readlines   python   and   word   return   coding   ext   

原文地址:https://www.cnblogs.com/rise0111/p/11563355.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!