朋友圈分析1
#-- conding:utf-8 --
from wxpy import *
from pyecharts import Pie,Bar
#1、創建機器人
bot = Bot(cache_path=True)
#2、查找朋友
Friends = bot.friends().search()[1:]
#3、朋友總數
total = len(Friends)
#初始化男女生人數為0
male = female = other = 0
遍歷計算男女生人數
for i in Friends:
if i.sex == 1:
male+=1
elif i.sex == 2:
female+=1
else:
other+=1
輸出計算結果
print(‘男生%d人,占比%2f%%’%(male,float(male/total)*100))
print(‘女生生%d人,占比%2f%%’%(female,float(female/total)*100))
print(‘未知性別%d人,占比%2f%%’%(other,float(other/total)*100))
畫pie圖
attr = [“男生”, “女生”, “未知”]
value = [male,female,other]
pie = Pie(“餅圖示例”,title_pos=‘center’)
pie.add("", attr, value, radius=[50, 75],is_label_show=True,legend_orient=“vertical”,legend_pos=“left”)
pie.render(’./pie-1.html’)
embed()
總結
- 上一篇: 总有朋友啊
- 下一篇: 计算机策略更新失败用户策略更新失败,升级