import jiebaimport matplotlibpyplot as pltfile = openpingjiatxt r encoding=utf-8txt = filereadwords = jiebalcuttxtcount = jiebadel_wordjiebadel_word:jiebadel_word!for word in words if lenword 1
import jieba import matplotlib.pyplot as plt
file = open("pingjia.txt", "r", encoding='utf-8') txt = file.read() words = jieba.lcut(txt) count = {}
for word in words: if len(word) < 1 or word == ',' or word == ':' or word == '!' or word == '的': continue else: count[word] = count.get(word, 0) + 1
top_words = sorted(count.items(), key=lambda x: x[1], reverse=True)[:10] # 取出频率前10的词 x = [word[0] for word in top_words] y = [word[1] for word in top_words]
plt.rcParams['font.sans-serif'] = ['SimHei'] plt.title("用户评价分析") plt.xlabel("评价") plt.ylabel("数量") plt.bar(x, y) plt.show(
原文地址: https://www.cveoy.top/t/topic/eUOK 著作权归作者所有。请勿转载和采集!