性别分析--微信数据分析(一)
生活随笔
收集整理的這篇文章主要介紹了
性别分析--微信数据分析(一)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
安裝
如果你還沒有安裝的話,推薦安裝一下微信分析的相關包
微信數據分析包準備(Python)
兩分鐘應該就可以搞定了
代碼
實現代碼:
import itchat import matplotlib.pyplot as pltplt.rcParams['font.sans-serif'] = ['SimHei'] # 步驟一(替換sans-serif字體) itchat.auto_login(hotReload=True)# 第一個就是自己 friendList = itchat.get_friends(update=True)[1:] # 0表示未知,1表示男性,2表示女性 sexDict = {}total = len(friendList) for friend in friendList:if not friend['Sex'] in sexDict:sexDict[friend['Sex']] = 0sexDict[friend['Sex']] += 1 unkonw = sexDict[0] male = sexDict[1] female = sexDict[2]# 顏色 colors = ['yellowgreen', 'lightskyblue', 'lightcoral'] # 標簽 labels = ['未知', '男性', '女性'] # 控制讓哪個塊向外一點(這里選的是中間的那個男性) explode = (0, 0.1, 0) plt.pie([unkonw, male, female], labels=labels, explode=explode, colors=colors, autopct='%1.1f%%') plt.show()總結
以上是生活随笔為你收集整理的性别分析--微信数据分析(一)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 微信数据分析包准备(Python)
- 下一篇: 微信好友数据打包下载--微信数据分析(二