大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。
Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺
主要代码如下:
排序出高频词
# -*- coding: utf-8 -*-""" from wordcloud import WordCloudimport matplotlib.pyplot as plt import jieba article = open('hlm.txt',encoding='UTF-8').read() dele = {'。','!','?','】','“','”','(',')',' ','》','《',','} jieba.add_word('贾宝玉') words = list(jieba.cut(article)) articleDict = {} articleSet = set(words)-dele for w in articleSet: if len(w)>1: articleDict[w] = words.count(w) articlelist = sorted(articleDict.items(),key = lambda x:x[1], reverse = True) cut_text = " ".join(words) 'print(cut_hlm)' mywc = WordCloud().generate(cut_hlm) plt.imshow(mywc)plt.axis("off") plt.show() ''' for i in range(20): print(articlelist[i]) import pandas as pd pd.DataFrame(data=articlelist).to_csv('test.csv',encoding='UTF-8') '''
红楼梦高频词:
红楼梦整篇小说:
成功排序出高频词:
生成词云如下:
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/167736.html原文链接:https://javaforall.net