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: continue else: count[word] = count.get(word, 0) + 1

exclude = ["可以", "的", "。", ":", "", "这样"] for key in list(count.keys()): if key in exclude: del count[key]

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(

import jiebaimport matplotlibpyplot as pltfile = openpingjiatxt r encoding=utf-8txt = filereadwords = jiebalcuttxtcount = for word in words # 使用 for 循环遍历每个词语并统计个数 if lenword 1 # 排除单个字的干扰使得输出结果为词

原文地址: https://www.cveoy.top/t/topic/eULw 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录