关键词搜索

源码搜索 ×
×

世界最强五百企业你都知道嘛 ?python带你走进它们的数据~

发布2022-04-20浏览287次

详情内容

导入模块

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
  • 1
  • 2
  • 3
  • 4
  • 5

代码

# 导入数据
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="https://files.jxasp.com:9443/image/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()
  • 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
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40

在这里插入图片描述

将国家列设置为索引

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="https://files.jxasp.com:9443/image/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()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

在这里插入图片描述

筛选出中国的世界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="https://files.jxasp.com:9443/image/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()

  • 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

在这里插入图片描述

相关技术文章

点击QQ咨询
开通会员
返回顶部
×
微信扫码支付
微信扫码支付
确定支付下载
请使用微信描二维码支付
×

提示信息

×

选择支付方式

  • 微信支付
  • 支付宝付款
确定支付下载