Python微信好友的性别分布问题,用文字输出及用饼状图输出。

#功能:微信性别比例饼状图

#pip install pyecharts 安装pyecharts

import itchat

from pyecharts import Pie #导入库pyecharts

#模拟微信登陆

itchat.auto_login(hotReload=True)

itchat.dump_login_status()

friends = itchat.get_friends(update=True)[:]#获取朋友数

total = len(friends) - 1

man = women = other = 0 #初始化

for friend in friends[0:] :#开始对男女进行分类

    sex = friend["Sex"]

    if sex == 1 :

        man += 1

    elif sex == 2 :

        women += 1

    else :

        other += 1

 

print("男性好友:%.2f" % man)

print("女性好友:%.2f" % women)

print("其他:%.2f" % other)

print("男性好友:%.2f%%" % (float(man) / total * 100))

print("女性好友:%.2f%%" % (float(women) / total * 100))

print("其他:%.2f%%" % (float(other) / total * 100))

#绘制图

Pie=Pie("微信性别比例饼状图")

Pie.add("",['男','女','其它'],[man,women,other],radius=[10,80],legend_text_color='blue',is_label_show=True)

Pie.render("weixin.html")

 

运行结果如下:

image.png

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值