大家好,我是java1234_小鋒老師,最近寫了一套【NLP輿情分析】基于python微博輿情分析可視化系統(flask+pandas+echarts)視頻教程,持續更新中,計劃月底更新完,感謝支持。今天講解詞云圖-微博評論詞云圖實現
視頻在線地址:
2026版【NLP輿情分析】基于python微博輿情分析可視化系統(flask+pandas+echarts+爬蟲) 視頻教程 (火爆連載更新中..)_嗶哩嗶哩_bilibili
課程簡介:
本課程采用主流的Python技術棧實現,Mysql8數據庫,Flask后端,Pandas數據分析,前端可視化圖表采用echarts,以及requests庫,snowNLP進行情感分析,詞頻統計,包括大量的數據統計及分析技巧。
實現了,用戶登錄,注冊,爬取微博帖子和評論信息,進行了熱詞統計以及輿情分析,以及基于echarts實現了數據可視化,包括微博文章分析,微博IP分析,微博評論分析,微博輿情分析。最后也基于wordcloud庫實現了詞云圖,包括微博內容詞云圖,微博評論詞云圖,微博評論用戶詞云圖等功能。
詞云圖-微博評論詞云圖實現
首先把微博評論詞云圖靜態網頁模版commentCloud.html放到templates下:
{% extends 'base.html' %}
{% block title %}微博評論詞云圖{% endblock %}
{% block content %}<div class="container-fluid"><div class="row"><div class="col-lg-12"><div class="card"><div class="card-header d-flex justify-content-between"><div class="header-title"><h4 class="card-title">微博評論詞云圖</h4></div><div class="header-action"><i data-toggle="collapse" data-target="#datatable-1" aria-expanded="false"><svg width="20" xmlns="http://www.w3.org/2000/svg" fill="none" viewbox="0 0 24 24"stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"d="M10 20l4-16m4 4l4 4-4 4M6 16l-4-4 4-4"></path></svg></i></div></div></div>
?</div></div>
?<div class="row"><div class="col-lg-12"><div class="card"><div class="card-body"><div id="main" style="width:100%;height:750px;text-align:center"><img style="width:40%" src="/static/comment_cloud.jpg" alt=""></div></div></div>
?</div></div></div>
{% endblock %}
page.py下新建commentCloud方法:
@pb.route('/commentCloud')
def commentCloud():"""微博評論詞云圖:return:"""# 只讀取前50條df = pd.read_csv('./fenci/comment_fre.csv', nrows=50)hotCommentWordList = [x[0] for x in df.values]str2 = ' '.join(hotCommentWordList)wordcloudUtil.genWordCloudPic(str2, 'comment_mask.jpg', 'comment_cloud.jpg')return render_template('commentCloud.html')