如何利用Python分析出微信朋友男女统计图
作者:人生苦短丨我爱python 时间:2021-12-03 15:46:09
写在前面
现在人人都有微信,一句“咱们加个微信呗”搭载了你我之间的友谊桥梁,浑然不知自己的微信朋友已经四五百了,甚至上千,几千的都有;然而那个是那个,谁是谁,是男是女都分不清楚了,今天咱们就来统计一下你微信朋友的男女比例,来看你平常喜欢加男性朋友还是女性朋友,哈哈,暴露了吧。
下面话不多说了,来一起看看详细的介绍吧
环境安装
有一个挺有意思的库是itchat,它是一个开源的微信个人接口,咱们就用itchat来统计自己微信朋友的性别比例,并且用柱状图呈现出来,使自己一目了然。
(1)首先在安装 itchat:
pip install itchat
(2)在安装matplotlib:
pip install matplotlib
登录微信
itchat.auto_login(hotReload=True)
运行程序的时候弹出的微信二维码,需要手机扫码登录微信,才可以继续执行代码以便于进行统计。
以下是完整的程序代码:
import itchat
import matplotlib.pyplot as plt
itchat.auto_login(hotReload=True)
friends=itchat.get_friends(update=True)[0:] #获取所有好友信息
male = female = other =0
for i in friends[1:]:
sex=i["Sex"]
if sex==1:
male+=1
elif sex==2:
female+=1
else:
other+=1
total=len(friends[1:])
print("男性好友: %.2f%%" % (float(male)/total*100) + "\n" +
"女性好友: %.2f%%" % (float(female) / total * 100) + "\n" +
"不明性别好友: %.2f%%" % (float(other) / total * 100))
plt.xlabel("sex")
plt.ylabel("count")
plt.title("Gender statistics")
a=plt.subplot(1,1,1)
plt.bar(10, male, facecolor='red', width=3, label='male')
plt.bar(15, female, facecolor='yellow', width=3, label='female')
plt.bar(20, other, facecolor='blue', width=3, label='other')
plt.legend()
plt.show()
运行以上代码可以得到微信好友的性别比例:
比如我的微信朋友统计画图如下:
从以上柱状图可以看出我的微信朋友统计,
男性好友: 57.99%;
女性好友: 34.32%;
不明性别好友: 7.69%;
可以看出我的男性朋友比女性朋友多得多,由此可以得出我是一个理工钢铁直男,几乎是没救的那种,哈哈哈,不知道大家的怎么样呢,一试便知,哈哈。
来源:https://www.jianshu.com/p/b4a80b310772
标签:python,分析,微信
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python 使用OpenCV进行曝光融合
2022-03-13 05:23:37
![](https://img.aspxhome.com/file/2023/3/102773_0s.jpg)
Python3实现英文字母转换哥特式字体实例代码
2023-08-04 10:28:11
![](https://img.aspxhome.com/file/2023/0/98880_0s.jpg)
php文件怎么打开 如何执行php文件
2023-11-15 05:51:46
![](https://img.aspxhome.com/file/2023/1/96241_0s.gif)
Xml Http抓取数据时乱码问题解决
2008-04-24 11:16:00
jQuery初学:find()方法及children方法的区别分析
2011-02-05 10:58:00
![](https://img.aspxhome.com/file/UploadPic/20112/5/20112511038177s.png)
PHP PDOStatement::setAttribute讲解
2023-06-04 02:48:47
在python中实现将一张图片剪切成四份的方法
2023-10-04 02:20:04
五种提高 SQL 性能的方法
2008-05-16 10:40:00
python启动办公软件进程(word、excel、ppt、以及wps的et、wps、wpp)
2022-06-12 23:09:48
Python supervisor强大的进程管理工具的使用
2021-04-15 09:11:58
![](https://img.aspxhome.com/file/2023/0/75150_0s.png)
PHP利用ChatGPT实现轻松创建用户注册页面
2023-05-25 09:22:16
PHP json格式和js json格式 js跨域调用实现代码
2023-11-22 05:20:18
asp如何在约定时间显示特定的提示信息?
2010-06-28 16:52:00
python matlibplot绘制3D图形
2023-05-21 18:47:36
![](https://img.aspxhome.com/file/2023/4/87724_0s.png)
解决django中form表单设置action后无法回到原页面的问题
2023-06-27 00:27:54
python3实现名片管理系统
2022-01-21 22:11:01
网站渗透常用Python小脚本查询同ip网站
2021-06-12 21:51:28
![](https://img.aspxhome.com/file/2023/1/95501_0s.png)
matplotlib.pyplot绘图显示控制方法
2023-07-03 15:44:20
![](https://img.aspxhome.com/file/2023/3/62903_0s.jpg)
Python学习之字典和集合的使用详解
2022-11-01 19:54:21
PHP实现登录的Cookie存储方案详解
2023-05-25 08:45:17