1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| import pandas as pd from pyecharts import options as opts from pyecharts.charts import Pie
filename=['beijing_AQI_2018.csv','shanghai_AQI_2018.csv','guangzhou_AQI_2018.csv','shenzhen_AQI_2018.csv'] quality_grade_count_list=[] for i in filename: data = pd.read_csv(i) quality_grade_statistics = data.groupby(['Quality_grade']) quality_grade_count = quality_grade_statistics['Quality_grade'].agg(['count']) quality_grade_count.reset_index(inplace=True) quality_grade_count = quality_grade_count.sort_values(by='count',ascending=False) quality_grade_count_list.append(quality_grade_count) p = ( Pie() .add('北京',[list(z) for z in zip(list(quality_grade_count_list[0]['Quality_grade']),list(quality_grade_count_list[0]['count']))], center=['30%','30%'],radius=['20%','40%']) .add('上海',[list(z) for z in zip(list(quality_grade_count_list[1]['Quality_grade']),list(quality_grade_count_list[1]['count']))], center=['60%','30%'],radius=['20%','40%']) .add('广州',[list(z) for z in zip(list(quality_grade_count_list[2]['Quality_grade']),list(quality_grade_count_list[2]['count']))], center=['30%','75%'],radius=['20%','40%']) .add('深圳',[list(z) for z in zip(list(quality_grade_count_list[3]['Quality_grade']),list(quality_grade_count_list[3]['count']))], center=['60%','75%'],radius=['20%','40%']) .set_global_opts(title_opts=opts.TitleOpts(title='2018年北上广深全年空气质量情况\n\t\tGiesen',pos_left='30%'), legend_opts=opts.LegendOpts(orient="vertical",pos_right='10%',pos_top='10%')) .set_series_opts(label_opts=opts.LabelOpts(formatter='{a}',position='center',font_size=20), tooltip_opts=opts.TooltipOpts(formatter='{a}<br/>{b}:{c}({d}%)')) ) p.render_notebook()
|