python 爬取七普人口并展示人口区间的概率分布( 二 )


import numpyimport pandas as pdimport matplotlib.pyplot as pltfrom pyecharts.charts import Barfrom pyecharts import options as optsdata = http://www.kingceram.com/post/pd.read_excel("各城市人口2.xlsx")data = http://www.kingceram.com/post/pd.DataFrame(data)people_count = data['count'].values.tolist()range_num = []labes = []j = 1for i in range(0,1700,100):range_num.append(i)labes.append(str(i)+"-"+str(j*100))j+=1range_num.append(5000)labes.pop(-1)labes.append("大于1600")print(range_num,labes)cuts = pd.cut(people_count,range_num,labels=labes)couts_range = cuts.value_counts().values.tolist()bar = Bar(init_opts=opts.InitOpts(width="2000px",height="700px",page_title="各个区间范围的城市数"))bar.add_xaxis(labes)bar.add_yaxis("", couts_range)bar.set_global_opts(xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=20)),title_opts=opts.TitleOpts(title="区间内的城市数量", subtitle="坐"),datazoom_opts=opts.DataZoomOpts(),)bar.render_notebook()bar.render('全国区间人口2.html')