前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >#python# #数据分析# 性别比例分析

#python# #数据分析# 性别比例分析

作者头像
滚神大人
发布2019-09-10 18:55:19
6130
发布2019-09-10 18:55:19
举报
文章被收录于专栏:趣Python趣Python

手头有一份性别比例的样本数据,清洗后只保留了性别信息,做了一个数据分析。

数据清洗和数据统计的代码就不贴了,贴性别比例pie图和性别比例趋势图的代码。

性别比例pie图:

代码语言:javascript
复制
def _plot_gender_stat_pie(self, fig, gender_stat, title):
   """
   fig : figure obj
   gender_stat : male / female stat
   title : figure title
   """
   def _explode(label, target='female'):
       if label == target:
            return 0.1
       else:
            return 0
   labels = ['male', 'female']
   expl = list(map(_explode, labels))
    plt.figure(fig, figsize=(7, 7))
   plt.pie(gender_stat, explode=expl, labels=labels, autopct="%5.2f%%")
   plt.title(title, bbox={'facecolor': '0.8', 'pad': 8})

平均性别比例:

年份比较图:

性别比例趋势图代码:

代码语言:javascript
复制
def _plot_gender_stat_line_bar(self, gender_stats):
   """
   gender_stat : male / female stats by year
   """        
   y = gender_stats
   x = range(0, len(y))   plt.figure(figsize=(10, 6)) 
    # line plot
   plt.plot(x, y, 'r.:')
    # plot text on each point
   for point_x, point_y in zip(x, y):
       plt.text(point_x, point_y, str('%.1f' %
                                      point_y), horizontalalignment='center')
    # bar plot
   plt.bar(x, y, width=0.5, color='g')
    plt.xlabel('time')
   plt.ylabel('rate')
   plt.title('male / female rate change', y=0.9)
   plt.show()
  • 样本数据有限,仅用来学习,无其他含义。
  • 是不是效益好的时候,男女性别比例就会小一些,效益不好或者初创期男女性别比例就会大一些?
  • 后面的趋势跟二胎政策也有一定关系。
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2017-12-16,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 趣Python 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档