概述
from pygal_maps_world.i18n import COUNTRIES import pygal.maps.world from pandas import DataFrame import pandas as pd import matplotlib.pyplot as plt from pylab import mpl def get_country_name(country_name): for code, name in COUNTRIES.items(): if name == country_name: return code return None # #mpl.rcParams['font.sans-serif'] = ['SimHei'] # mpl.rcParams['font.sans-serif'] = ['Microsoft YaHei'] # 指定默认字体:解决plot不能显示中文问题 # mpl.rcParams['axes.unicode_minus'] = False res = pd.read_csv(r'C:UsersAdministratorDesktopdata.csv') res.rename(columns={'Unnamed: 0': 'country'}, inplace=True) res.rename(columns={'Unnamed: 1': 'year'}, inplace=True) newdata = DataFrame() newdata['Country'] = res.country[1:] newdata['Year'] = res.year[1:] newdata['bothsex'] = res['Life expectancy at birth (years)'][1:] newdata['male'] = res['Life expectancy at birth (years).1'][1:] newdata['female'] = res['Life expectancy at birth (years).2'][1:] # finaldata = DataFrame(newdata[newdata['Country'] == 'China'][['bothsex', 'male', 'female']], dtype='float64') finaldata = DataFrame(newdata[newdata['Year']==' 2016'][['bothsex']], dtype='float64') finaldata['Country'] = newdata[newdata['Year']==' 2016'][['Country']] wm = pygal.maps.world.World() age = {} age1 = {} age2 = {} age3 = {} for i in finaldata.values: age[get_country_name(i[1])] = i[0] for cc, pop in age.items(): if pop < 70.0: age1[cc] = pop elif pop < 78.0: age2[cc] = pop else: age3[cc] = pop wm.add('年龄小于70岁', age1) wm.add('年龄小于78岁', age2) wm.add('年龄大于78岁', age3) wm.render_to_file('age.svg') 下载数据链接:http://apps.who.int/gho/data/node.main.1?lang=en
最后
以上就是尊敬泥猴桃为你收集整理的python 世界人口预期寿命分析的全部内容,希望文章能够帮你解决python 世界人口预期寿命分析所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复