博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
数据分析小实践:统计每个国家存在心理健康问题的平均年龄
阅读量:7310 次
发布时间:2019-06-30

本文共 1289 字,大约阅读时间需要 4 分钟。

# -*- coding:utf-8 -*-"""统计每个国家存在心理健康问题的平均年龄"""import csvimport matplotlib.pyplot as pltimport numpy as npimport matplotlibdata_depth = "./data/survey.csv"dict = {}result = {}matplotlib.use('qt4agg')#指定默认字体  matplotlib.rcParams['font.sans-serif']=['SimHei']matplotlib.rcParams['font.family']='sans-serif'with open(data_depth,'r',newline='') as data:    rows = csv.reader(data)    for i,row in enumerate(rows):        if i == 0:            continue        country = row[3]        age = row[1]        if country not in dict:            dict[country] = [0,0]        dict[country][0] = dict[country][0] + int(row[1])        dict[country][1] = dict[country][1] + 1for key in dict:    result[key] = dict[key][0] / dict[key][1]sorted_result = sorted(result.items(),key=lambda asd:asd[1],reverse=True)del sorted_result[0]print(sorted_result)x_data = []for i in sorted_result:    x_data.append(i[0])y_data =[]for i in sorted_result:    y_data.append(i[1])print(sorted_result.__len__())fig = plt.figure()ax = fig.add_subplot(1,1,1)ax.bar(np.arange(10),y_data[:10],color='b',alpha = 0.5)ax.set_xticks(np.arange(10)+0.4)ax.set_xticklabels(x_data[:10])ax.set_xlabel('国家')ax.set_ylabel('平均年龄')ax.set_title("排名前10的国家存在心理健康问题的科技工作者平均年龄")plt.show()

  

转载于:https://www.cnblogs.com/zhangshilin/p/6914390.html

你可能感兴趣的文章
Sublime使用snippet实现快速输入代码块
查看>>
DDPush-任意门推送-概述
查看>>
Exchange 2007收件人管理
查看>>
解决kvm虚拟机直接访问宿主机器上面某个磁盘问题
查看>>
读后感(一直埋头学习的兄弟们)
查看>>
使用Cisco Packet Tracer之DHCP服务于不同的VLAN
查看>>
windows下生成https证书
查看>>
十六进制数组成的字符串 转换成 对应的ASCII字符串
查看>>
Linux上的mysql集群
查看>>
CompletionService小记
查看>>
使用Supervisor管理Redis进程
查看>>
Android开发之模拟器访问本地服务器需注意事项
查看>>
ip source route
查看>>
2015年终总结
查看>>
squid实现反向代理!!!
查看>>
.NET的Ajax请求数据提交
查看>>
openssl的加密、解密以及构建私有CA
查看>>
【Python基础 08】函数基础
查看>>
MySQL查找SQL耗时瓶颈SHOW profiles
查看>>
Myeclipse优化配置
查看>>