Python 实践 | wxpy-统计微信朋友

今天是工作日,就不写太多了,简单写一下上周末学习到的新库wxpy的一些微信朋友统计功能,给各位参考学习一下。(我用的是python3)


640?wx_fmt=png


1)首先肯定是要安装啦~

直接在本机状态下命令窗口敲入:pip install -U wxpy

640?wx_fmt=png



2)扫码登陆个人微信

from wxpy import *

bot = Bot(cache_path=True)


640?wx_fmt=png



3)统计微信朋友人数top10省份

friends_stat = bot.friends().stats()

friend_loc = [ ] #每一个元素是一个二元列表,分别存储地区和人数信息

for province, count in friends_stat["province"].items():

    if province != "": 

        friend_loc.append([province, count])


# 对人数倒序排序

friend_loc.sort(key=lambda x: x[1], reverse=True)


# 打印人数最多的10个地区

for item in friend_loc[:10]:

    print (item[0], item[1])


640?wx_fmt=png



4)统计微信朋友人数top10城市

friend_loc = [ ] 

for city, count in friends_stat["city"].items():

    if city != "": 

        friend_loc.append([city, count])


friend_loc.sort(key=lambda x: x[1], reverse=True)


for item in friend_loc[:10]:

    print (item[0], item[1])


640?wx_fmt=png



5)统计微信朋友性别分布

for sex, count in friends_stat["sex"].items():

    # 1代表MALE, 2代表FEMALE

    if sex == 1:

        print ("MALE %d" % count)

    elif sex == 2:

        print ("FEMALE %d" % count)


640?wx_fmt=png



6)用excel画出来

640?wx_fmt=png

640?wx_fmt=png

640?wx_fmt=png

 
 



—End—


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值