zoukankan      html  css  js  c++  java
  • 使用itchat分析自己的微信(1)

    1.准备工作

    • 安装itchat pip install itchat参考
    • itchat内部函数

    2.个人微信男女比例分析

    '''
        Have fun:itchat
        Author:杨   景
        Time:2018.01.14
    '''
    #-*- utf-8 -*-   
    import itchat
    import pandas as pd
    import matplotlib.pyplot as plt
    
    try:
        itchat.login()
    except AttributeError:
        itchat.auto_login(enableCmdQR=True)
        itchat.run(debug=True)
    else:
        pass
    friends=pd.DataFrame(itchat.get_friends(update=True))
    #Sex statistics
    male=famale=unkown=0
    for item in friends['Sex']:
        if item==0:
            unkown+=1
        if item==1:
            famale+=1
        if item==2:
            male+=1
    
    total=len(friends['Sex'])
    percentage=[male/total,famale/total,unkown/total]
    fig=plt.figure()
    ax=fig.add_subplot(1,1,1)
    ax.set_title(u'male famale ratio')
    ax.set_ylim([0,1])
    ticks=ax.set_xticks([1,2,3])
    labels=ax.set_xticklabels(['male','famale','unkown'])
    #p_str= percentage.apply(lambda x: format(x, '.2%'))
    def autolabel(rects):
        # attach some text labels
        for rect in rects:
            height = rect.get_height()
            ax.text(rect.get_x()+rect.get_width()/2., 1.05*height, '%.2f'%float(height),
                    ha='center', va='bottom')
    bar=ax.bar(left=[1,2,3], height=percentage, width=0.7)
    autolabel(bar)
    plt.show()
    

    如图所示

    哈哈,没想到还是女性朋友多

  • 相关阅读:
    C++ 虚成员函数和动态联编
    C++ 多态公有继承
    C++ 继承特性
    C++ 公有派生
    C++ 基类与派生类
    C++ 类继承
    C++ 伪私有方法
    C++ new失败
    mysql用户授权
    linux时间设置
  • 原文地址:https://www.cnblogs.com/yangjing000/p/8283071.html
Copyright © 2011-2022 走看看