首页 > 其他 > 详细

jieba库的使用和好用的词云

时间:2019-04-03 00:14:59      阅读:161      评论:0      收藏:0      [点我收藏+]

# -*- coding: utf-8 -*-

def get_text():
txt = open("1.txt", "r", encoding=‘UTF-8‘).read()
txt = txt.lower()
for ch in ‘!"#$%&()*+,-./:;<=>?@[\\]^_‘{|}~‘:
txt = txt.replace(ch, " ") # 将文本中特殊字符替换为空格
return txt

file_txt = get_text()
words = file_txt.split() # 对字符串进行分割,获得单词列表
counts = {}

for word in words:
if len(word) == 1:
continue
else:
counts[word] = counts.get(word, 0) + 1

items = list(counts.items())
items.sort(key=lambda x: x[1], reverse=True)

for i in range(5):
word, count = items[i]
print("{0:<5}->{1:>5}".format(word, count))

技术分享图片

 

jieba库的使用和好用的词云

原文:https://www.cnblogs.com/meirenjiajing/p/10646127.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!