数据分析小白笔记(一)

数据分析 小白笔记

1、文本分词


import jieba

s = "中国新闻网8677条新闻"

cut = jieba.lcut(s)

print(cut)

2、去停用词

下载停用词库


import jieba

stop_words = []

s = "中国0新闻网不问8677条新闻"

def load_stop_words(path = 'stop_words.txt'):
    with open(path,'r') as f:
        for line in f:
            content = line.strip()
            stop_words.append(content)


load_stop_words()
lcut = jieba.lcut(s)
cut = [x for x in lcut if x not in stop_words]
print(cut)

你可能感兴趣的:(数据分析小白笔记(一))