平常我們爬的評論、彈幕等等,數量又多又密,根本看不過來,這時候資料分析的作用來了,今天我們就試試用Python根據這些資料,來繪制詞云圖進行熱詞分析,
知識點
- 檔案讀寫
- 基礎語法
- 字串處理
- 檔案生成
- 資料構建
代碼展示
# 匯入系統包 import platform from flask import Flask, render_template from pyecharts import options as opts from pyecharts.charts import * web = Flask(__name__) # 構建資料 # Python學習交流群:708525271 # 更多代碼、教程、電子書等等在群里自取即可 words = [("花鳥市場", 1446), ("汽車", 928), ("視頻", 906), ("電視", 825), ("動漫", 486), ("音樂", 53), ("直播", 163), ("廣播電臺", 86), ("戲曲曲藝", 17), ("演出票務", 6), ("給陌生的你聽", 1), ("資訊", 1437), ("科技資訊", 313), ("旅游網站偏好", 512), ("出國游", 382), ("考試培訓", 473), ("印刷列印", 66), ("知識產權", 32), ("翻譯", 22), ("安全安保", 9), ("公關服務", 8), ("商旅服務", 2), ("展會服務", 2), ("辦公學習", 28), ("應用市場", 23),("母嬰育兒", 14), ("游戲", 946), ("手機游戲", 565), ("PC游戲", 353), ("網頁游戲", 254), ("游戲機", 188), ("模擬輔助", 166), ("護膚品", 177), ("彩妝", 133), ("家居飾品", 29), ("家居日常用品", 10), ("生活服務", 883), ("物流配送", 536), ("家政服務", 108), ("攝影服務", 49), ("搬家服務", 38), ("手相", 32), ("公益", 90), ] def wordCluond_charts() -> WordCloud(): # 實體化物件 wordCluond = WordCloud() wordCluond.add(series_name="熱點分析", data_pair=words, word_size_range=[6, 66], textstyle_opts=opts.TextStyleOpts(font_family="cursive")) # 全域置標題、標簽 wordCluond.set_global_opts( title_opts=opts.TitleOpts(title="如何繪制詞云圖展示熱點詞語分析", subtitle="菜鳥實戰,堅持學習!"), ) return wordCluond # 獲取物件 p = wordCluond_charts() # 繪制圖形,path為指定路徑,生成HTML檔案的一個路徑 p.render('./templates/wordCluond_charts.html') # 添加路由顯示圖表 @web.route('/') def index(): return render_template('wordCluond_charts.html') if __name__ == "__main__": # 運行專案 web.run(debug=False) print("Python 版本", platform.python_version())
效果展示
可以看到,當前花鳥市場最顯眼,其次是資訊,這樣子熱詞一目了然,
好了,今天的分享就到這里,
最后給大家分享一套Python教程:代碼總是學完就忘記?100個Python實戰專案!讓你沉迷學習丨學以致用丨下一個Python大神就是你!
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/517543.html
標籤:其他
上一篇:Python學習:print 和return 的區別
下一篇:Java 集合簡介 一
