qshhl

前言

哪个国家的世界五百强企业数量最多?今天带你用python来处理数据,并实现数据可视化,解决对现有数据产生的疑问。

本次代码是在 Jupyter Notebook 里面编写的

先导入本次代码需要的模块

import pandas as pd
from pyecharts.charts import *
from pyecharts import options as opts
from pyecharts.commons.utils import JsCode
from pyecharts.globals import ThemeType

 

导入数据

data = pd.read_excel(\'2021年世界五百强排行榜.xlsx\')
data.head(5)

 

统计世界500强企业各个国家之间的占比

pie = Pie(init_opts=opts.InitOpts(theme=\'light\',
                                  width=\'800px\',
                                  height=\'700px\'))

data_x = data1[\'国家\'].tolist()
data_y = data1[\'排名\'].tolist()
                                  
pie.add("",
        [list(z) for z in zip(data_x, data_y)],
        radius=["35%", "55%"]
        )
pie.set_series_opts(label_opts=opts.LabelOpts(position="insideLeft",
                                              font_size=12,
                                              color=\'rgba(0,0,0,0.5)\',
                                              font_weight=\'bold\',
                                              formatter=\'{b}:{d}%\'),
                    itemstyle_opts={\'normal\': {
                                                \'opacity\': 1,  # 透明度
                                                \'shadowColor\': \'rgba(0, 0, 0, 0.2)\',  # 阴影颜色
                                                \'shadowBlur\': 5,  # 阴影大小
                                                \'shadowOffsetY\': 5,  # Y轴方向阴影偏移
                                                \'shadowOffsetX\': 5,  # x轴方向阴影偏移
                                        }
                                    }
                   )

pie.set_global_opts(legend_opts=opts.LegendOpts(is_show=True, pos_left=\'right\', pos_top=\'center\', orient=\'vertical\'),
                    title_opts=opts.TitleOpts(title="2021年世界各国500强企业占比", pos_top=\'center\', pos_left=\'center\', 
                                              title_textstyle_opts=opts.TextStyleOpts(font_size=16)),
                                              visualmap_opts=opts.VisualMapOpts( 
                                                                                min_=0,
                                                                                max_=200,
                                                                                ))    
                                                                                                                         
pie.render_notebook()

 

将国家列设置为索引

bar = Bar(init_opts=opts.InitOpts(theme=ThemeType.PURPLE_PASSION))
bar.add_yaxis("世界500强企业数量", data1[\'排名\'].tolist())
bar.set_global_opts(title_opts=opts.TitleOpts(title="每日电量统计表"),toolbox_opts=opts.ToolboxOpts(),xaxis_opts=opts.AxisOpts(name_rotate=60,axislabel_opts={"rotate":45}))
bar.render_notebook()
# 绘制直方图来显示
# 线性渐变
color_js = """new echarts.graphic.LinearGradient(0, 1, 0, 0,
    [{offset: 0, color: \'#008B8B\'}, {offset: 1, color: \'#FF6347\'}], false)"""

bar = Bar(init_opts=opts.InitOpts(theme=ThemeType.DARK))
bar.add_xaxis(data1.index.tolist())
bar.add_yaxis("世界500强企业数量", data1[\'排名\'].tolist(),itemstyle_opts=opts.ItemStyleOpts(color=JsCode(color_js)))
bar.set_global_opts(title_opts=opts.TitleOpts(title="2021年各国世界500强企业统计",subtitle=\'\',pos_left=\'center\',pos_top=\'3%\'), 
                    toolbox_opts=opts.ToolboxOpts(),
                    xaxis_opts=opts.AxisOpts(name_rotate=60,axislabel_opts={"rotate":45}),
                   legend_opts=opts.LegendOpts(is_show=True,
                                                 pos_left=\'80%\',
                                                 pos_bottom=\'90%\'))
bar.render_notebook()

 

筛选出中国的世界500强企业并进行数据可视化分析

# m_df = df.groupby([\'行业\'])[\'存活天数\'].mean().reset_index()
data2.sort_values(by=\'排名\',ascending=False, inplace=True)
data_x = data2[\'字段2\'].tolist()
data_y = data2[\'排名\'].tolist()

bar = Bar(init_opts=opts.InitOpts(theme=\'light\',
                                  width=\'1000px\',
                                  height=\'900px\'))
bar.add_xaxis(data_x)
bar.add_yaxis(\'平均存活天数\', [int(i) for i in data_y])
bar.set_series_opts(label_opts=opts.LabelOpts(position="insideLeft",
                                              font_size=12,
                                              font_weight=\'bold\',
                                              formatter=\'{b}:{c}\'))
bar.set_global_opts(title_opts=opts.TitleOpts(title="2021年中国世界500强企业城市分布", pos_top=\'2%\', pos_left=\'center\', 
                                              title_textstyle_opts=opts.TextStyleOpts(font_size=16)),
                    legend_opts=opts.LegendOpts(is_show=False),
                    xaxis_opts=opts.AxisOpts(is_show=False, is_scale=True),
                    yaxis_opts=opts.AxisOpts(is_show=False),
                    visualmap_opts=opts.VisualMapOpts( 
                                          max_=3000,
                                          min_=1500,
                                          is_piecewise=False,
                                          dimension=0,
                                          range_color=[\'rgba(238,25,38,1)\', \'rgba(289,112,147,0.4)\'])
                                      )
bar.reversal_axis()
bar.render_notebook()

 

分类:

技术点:

相关文章:

  • 2021-11-02
  • 2021-12-14
  • 2021-11-01
  • 2022-01-01
  • 2021-08-04
  • 2021-12-30
  • 2022-12-23
  • 2021-06-17
猜你喜欢
  • 2022-01-07
  • 2021-10-06
  • 2022-01-20
  • 2022-02-14
  • 2021-12-01
  • 2021-12-18
  • 2022-02-06
相关资源
相似解决方案