import jieba
# 一般过滤
def chinese_cut1(text):
return ' '.join(jieba.cut(text, cut_all = False)) # 精确模式
datacutted = data.apply(chinese_cut1)
词性过滤
import jieba.posseg
# 词性过滤
def chinese_cut2(text):
result = jieba.posseg.cut(text)
return ' '.join(x.word for x in result if x.flag == 'a' or x.flag == 'n' or x.flag == 'v')
datacutted = data.apply(chinese_cut2)
自定义词典
- 词典:UTF-8 编码,一词一条,空格间隔,每条 3 个特征,word 为词(必须),freq 为词频,word_type 为词性
jieba.load_userdict('dict.txt') # 自定义词典
# 动态修改词典
jieba.add_word('newword', freq = 10, tag = 'nz') # 添加自定义词
jieba.del_word('word') # 删除自定义词
jieba.suggest_freq(line.strip(), True) for line in open('dict.txt', 'r', encoding = 'utf8') # 批量修改词频
网友评论