奥运会数据分析

本项目将会从以下角度来呈现奥运会历史:

  1. 1、🏆各国累计奖牌数;

  2. 2、⚽️各项运动产生金牌数

  3. 3、⛳️运动员层面

    • 参赛人数趋势

    • 女性参赛比例趋势

    • 获得金牌最多的运动员

    • 获得奖牌/金牌比例

    • 各项目运动员平均体质数据

  4. 4、主要国家表现

    • 🇨🇳中国表现

    • 🇺🇸美国表现

  5. 5、💥被单个国家统治的奥运会项目

  6. 6、🏅️2020东京奥运会金牌分布图

  7. 一、导入库

  8. import pandas as pd
    import numpy as np
    import pyecharts
    from pyecharts.charts import *
    from pyecharts import options as opts
    from pyecharts.commons.utils import JsCode
    
    athlete_data = pd.read_csv('athlete_events.csv')
    noc_region = pd.read_csv('noc_regions.csv')# 关联代表国家
    data = pd.merge(athlete_data, noc_region, on='NOC', how='left')
    data.head()

    0cc7b0bdf8dc4891a099b78f4a51e784.png

    medal_data = data.groupby(['Year', 'Season', 'region', 'Medal'])['Event'].nunique().reset_index()
    medal_data.columns = ['Year', 'Season', 'region', 'Medal', 'Nums']                                      
    medal_data = medal_data.sort_values(by="Year" , ascending=True) 

     

    def medal_stat(year, season='Summer'):t_data = medal_data[(medal_data['Year'] <= year) & (medal_data['Season'] == season)]t_data = t_data.groupby(['region', 'Medal'])['Nums'].sum().reset_index()t_data = t_data.set_index(['region', 'Medal']).unstack().reset_index().fillna(0, inplace=False)t_data = sorted([(row['region'][0], int(row['Nums']['Gold']), int(row['Nums']['Silver']), int(row['Nums']['Bronze'])) for _, row in t_data.iterrows()], key=lambda x: x[1]+x[2]+x[3], reverse=True)[:20] return t_data

    二、可视化展示

  9. 1、累计奖牌数

  10. 夏季奥运会 & 冬季奥运会分别统计

  11. 🏖️夏季奥运会开始于1896年雅典奥运会;

  12. ❄️冬季奥运会开始于1924年慕尼黑冬奥会;

  13. medal_data = data.groupby(['Year', 'Season', 'region', 'Medal'])['Event'].nunique().reset_index()
    medal_data.columns = ['Year', 'Season', 'region', 'Medal', 'Nums']                                      
    medal_data = medal_data.sort_values(by="Year" , ascending=True) 
    def medal_stat(year, season='Summer'):t_data = medal_data[(medal_data['Year'] <= year) & (medal_data['Season'] == season)]t_data = t_data.groupby(['region', 'Medal'])['Nums'].sum().reset_index()t_data = t_data.set_index(['region', 'Medal']).unstack().reset_index().fillna(0, inplace=False)t_data = sorted([(row['region'][0], int(row['Nums']['Gold']), int(row['Nums']['Silver']), int(row['Nums']['Bronze'])) for _, row in t_data.iterrows()], key=lambda x: x[1]+x[2]+x[3], reverse=True)[:20] return t_data

    1.1各国夏奥会累计奖牌数

  14. 截止2016年夏季奥运会,美俄分别获得了2544和1577枚奖牌,位列一二位;

  15. 中国由于参加奥运会时间较晚,截止2016年累计获得了545枚奖牌,位列第七位;

  16. year_list = sorted(list(set(medal_data['Year'].to_list())), reverse=True)tl = Timeline(init_opts=opts.InitOpts(theme='dark', width='1000px', height='1000px'))
    tl.add_schema(is_timeline_show=True,is_rewind_play=True, is_inverse=False,label_opts=opts.LabelOpts(is_show=False))for year in year_list:t_data = medal_stat(year)[::-1]bar = (Bar(init_opts=opts.InitOpts()).add_xaxis([x[0] for x in t_data]).add_yaxis("铜牌🥉", [x[3] for x in t_data], stack='stack1',itemstyle_opts=opts.ItemStyleOpts(border_color='rgb(220,220,220)',color='rgb(218,165,32)')).add_yaxis("银牌🥈", [x[2] for x in t_data], stack='stack1',itemstyle_opts=opts.ItemStyleOpts(border_color='rgb(220,220,220)',color='rgb(192,192,192)')).add_yaxis("金牌🏅️", [x[1] for x in t_data], stack='stack1',itemstyle_opts=opts.ItemStyleOpts(border_color='rgb(220,220,220)',color='rgb(255,215,0)')).set_series_opts(label_opts=opts.LabelOpts(is_show=True, position='insideRight',font_style='italic'),).set_global_opts(title_opts=opts.TitleOpts(title="各国累计奖牌数(夏季奥运会)"),xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=45)),legend_opts=opts.LegendOpts(is_show=True),graphic_opts=[opts.GraphicGroup(graphic_item=opts.GraphicItem(rotation=JsCode("Math.PI / 4"),bounding="raw",right=110,bottom=110,z=100),children=[opts.GraphicRect(graphic_item=opts.GraphicItem(left="center", top="center", z=100),graphic_shape_opts=opts.GraphicShapeOpts(width=400, height=50),graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(fill="rgba(0,0,0,0.3)"),),opts.GraphicText(graphic_item=opts.GraphicItem(left="center", top="center", z=100),graphic_textstyle_opts=opts.GraphicTextStyleOpts(text=year,font="bold 26px Microsoft YaHei",graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(fill="#fff"),),),],)],).reversal_axis())tl.add(bar, year)tl.render_notebook()

21ab79f8182f4cacabeb1eb22c5e17db.png

year_list = sorted(list(set(medal_data['Year'][medal_data.Season=='Winter'].to_list())), reverse=True)tl = Timeline(init_opts=opts.InitOpts(theme='dark', width='1000px', height='1000px'))
tl.add_schema(is_timeline_show=True,is_rewind_play=True, is_inverse=False,label_opts=opts.LabelOpts(is_show=False))for year in year_list:t_data = medal_stat(year, 'Winter')[::-1]bar = (Bar(init_opts=opts.InitOpts(theme='dark')).add_xaxis([x[0] for x in t_data]).add_yaxis("铜牌🥉", [x[3] for x in t_data], stack='stack1',itemstyle_opts=opts.ItemStyleOpts(border_color='rgb(220,220,220)',color='rgb(218,165,32)')).add_yaxis("银牌🥈", [x[2] for x in t_data], stack='stack1',itemstyle_opts=opts.ItemStyleOpts(border_color='rgb(220,220,220)',color='rgb(192,192,192)')).add_yaxis("金牌🏅️", [x[1] for x in t_data], stack='stack1',itemstyle_opts=opts.ItemStyleOpts(border_color='rgb(220,220,220)',color='rgb(255,215,0)')).set_series_opts(label_opts=opts.LabelOpts(is_show=True, position='insideRight',font_style='italic'),).set_global_opts(title_opts=opts.TitleOpts(title="各国累计奖牌数(冬季奥运会)"),xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=45)),legend_opts=opts.LegendOpts(is_show=True),graphic_opts=[opts.GraphicGroup(graphic_item=opts.GraphicItem(rotation=JsCode("Math.PI / 4"),bounding="raw",right=110,bottom=110,z=100),children=[opts.GraphicRect(graphic_item=opts.GraphicItem(left="center", top="center", z=100),graphic_shape_opts=opts.GraphicShapeOpts(width=400, height=50),graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(fill="rgba(0,0,0,0.3)"),),opts.GraphicText(graphic_item=opts.GraphicItem(left="center", top="center", z=100),graphic_textstyle_opts=opts.GraphicTextStyleOpts(text='截止{}'.format(year),font="bold 26px Microsoft YaHei",graphic_basicstyle_opts=opts.GraphicBasicStyleOpts(fill="#fff"),),),],)],).reversal_axis())tl.add(bar, year)tl.render_notebook()

9a6a549295424e5698b1eb3071a878cd.png

 

2、各项运动产生金牌数

基于2016年夏奥会和2014年冬奥会统计;

  • 🏃田径 & 游泳是大项,在2016年夏奥会上分别产生了47和34枚金牌;
background_color_js = """new echarts.graphic.RadialGradient(0.5, 0.5, 1, [{offset: 0,color: '#696969'}, {offset: 1,color: '#000000'}])"""tab = Tab()
temp = data[(data['Medal']=='Gold') & (data['Year']==2016) & (data['Season']=='Summer')]event_medal = temp.groupby(['Sport'])['Event'].nunique().reset_index()
event_medal.columns = ['Sport', 'Nums']                                      
event_medal = event_medal.sort_values(by="Nums" , ascending=False) pie = (Pie(init_opts=opts.InitOpts(bg_color=JsCode(background_color_js), width='1000px', height='800px')).add('金牌🏅️', [(row['Sport'], row['Nums']) for _, row in event_medal.iterrows()],radius=["30%", "75%"],rosetype="radius").set_global_opts(title_opts=opts.TitleOpts(title="2016年夏季奥运会各项运动产生金牌占比", pos_left="center",title_textstyle_opts=opts.TextStyleOpts(color="white", font_size=20),     ),legend_opts=opts.LegendOpts(is_show=False)).set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {d}%"),tooltip_opts=opts.TooltipOpts(trigger="item", formatter="{a} <br/>{b}: {c} ({d}%)"),))
tab.add(pie, '2016年夏奥会')temp = data[(data['Medal']=='Gold') & (data['Year']==2014) & (data['Season']=='Winter')]event_medal = temp.groupby(['Sport'])['Event'].nunique().reset_index()
event_medal.columns = ['Sport', 'Nums']                                      
event_medal = event_medal.sort_values(by="Nums" , ascending=False) pie = (Pie(init_opts=opts.InitOpts(bg_color=JsCode(background_color_js), width='1000px', height='800px')).add('金牌🏅️', [(row['Sport'], row['Nums']) for _, row in event_medal.iterrows()],radius=["30%", "75%"],rosetype="radius").set_global_opts(title_opts=opts.TitleOpts(title="2014年冬季奥运会各项运动产生金牌占比", pos_left="center",title_textstyle_opts=opts.TextStyleOpts(color="white", font_size=20),     ),legend_opts=opts.LegendOpts(is_show=False)).set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {d}%"),tooltip_opts=opts.TooltipOpts(trigger="item", formatter="{a} <br/>{b}: {c} ({d}%)"),))
tab.add(pie, '2014年冬奥会')
tab.render_notebook()
Out[7]:

33f39e6655784f0dad80ce16b4b8a10b.png

 

3、运动员层面

3.1、历年参赛人数趋势

  • 从人数来看,每届夏奥会参赛人数都是冬奥会的4-5倍;

  • 整体参赛人数是上涨趋势,但由于历史原因也出现过波动,如1980年莫斯科奥运会层遭遇65个国家抵制;

  • athlete = data.groupby(['Year', 'Season'])['Name'].nunique().reset_index()
    athlete.columns = ['Year', 'Season', 'Nums']                                      
    athlete = athlete.sort_values(by="Year" , ascending=True) x_list, y1_list, y2_list = [], [], []for _, row in athlete.iterrows():x_list.append(str(row['Year']))if row['Season'] == 'Summer':y1_list.append(row['Nums'])y2_list.append(None)else:y2_list.append(row['Nums'])y1_list.append(None)background_color_js = ("new echarts.graphic.LinearGradient(1, 1, 0, 0, ""[{offset: 0, color: '#008B8B'}, {offset: 1, color: '#FF6347'}], false)"
    )line = (Line(init_opts=opts.InitOpts(bg_color=JsCode(background_color_js), width='1000px', height='600px')).add_xaxis(x_list).add_yaxis("夏季奥运会", y1_list, is_smooth=True, is_connect_nones=True,symbol="circle",symbol_size=6,linestyle_opts=opts.LineStyleOpts(color="#fff"),label_opts=opts.LabelOpts(is_show=False, position="top", color="white"),itemstyle_opts=opts.ItemStyleOpts(color="green", border_color="#fff", border_width=3),tooltip_opts=opts.TooltipOpts(is_show=True)).add_yaxis("冬季季奥运会", y2_list, is_smooth=True, is_connect_nones=True, symbol="circle",symbol_size=6,linestyle_opts=opts.LineStyleOpts(color="#FF4500"),label_opts=opts.LabelOpts(is_show=False, position="top", color="white"),itemstyle_opts=opts.ItemStyleOpts(color="red", border_color="#fff", border_width=3),tooltip_opts=opts.TooltipOpts(is_show=True)).set_series_opts(markarea_opts=opts.MarkAreaOpts(label_opts=opts.LabelOpts(is_show=True, position="bottom", color="white"),data=[opts.MarkAreaItem(name="第一次世界大战", x=(1914, 1918)),opts.MarkAreaItem(name="第二次世界大战", x=(1939, 1945)),])).set_global_opts(title_opts=opts.TitleOpts(title="历届奥运会参赛人数",pos_left="center",title_textstyle_opts=opts.TextStyleOpts(color="white", font_size=20),),legend_opts=opts.LegendOpts(is_show=True, pos_top='5%',textstyle_opts=opts.TextStyleOpts(color="white", font_size=12)),xaxis_opts=opts.AxisOpts(type_="value",min_=1904,max_=2016,boundary_gap=False,axislabel_opts=opts.LabelOpts(margin=30, color="#ffffff63",formatter=JsCode("""function (value) {return value+'年';}""")),axisline_opts=opts.AxisLineOpts(is_show=False),axistick_opts=opts.AxisTickOpts(is_show=True,length=25,linestyle_opts=opts.LineStyleOpts(color="#ffffff1f"),),splitline_opts=opts.SplitLineOpts(is_show=True, linestyle_opts=opts.LineStyleOpts(color="#ffffff1f")),),yaxis_opts=opts.AxisOpts(type_="value",position="right",axislabel_opts=opts.LabelOpts(margin=20, color="#ffffff63"),axisline_opts=opts.AxisLineOpts(linestyle_opts=opts.LineStyleOpts(width=2, color="#fff")),axistick_opts=opts.AxisTickOpts(is_show=True,length=15,linestyle_opts=opts.LineStyleOpts(color="#ffffff1f"),),splitline_opts=opts.SplitLineOpts(is_show=True, linestyle_opts=opts.LineStyleOpts(color="#ffffff1f")),),)
    )line.render_notebook()

    888a1d96d94246d88cd8e95b119b1d09.png

    3.2、历年女性运动员占比趋势

    一开始奥运会基本是「男人的运动」,女性运动员仅为个位数,到近几届奥运会男女参赛人数基本趋于相等;

  • # 历年男性运动员人数
    m_data = data[data.Sex=='M'].groupby(['Year', 'Season'])['Name'].nunique().reset_index()
    m_data.columns = ['Year', 'Season', 'M-Nums']                                      
    m_data = m_data.sort_values(by="Year" , ascending=True) # 历年女性运动员人数
    f_data = data[data.Sex=='F'].groupby(['Year', 'Season'])['Name'].nunique().reset_index()
    f_data.columns = ['Year', 'Season', 'F-Nums']                                      
    f_data = f_data.sort_values(by="Year" , ascending=True) t_data = pd.merge(m_data, f_data, on=['Year', 'Season'])
    t_data['F-rate'] = round(t_data['F-Nums'] / (t_data['F-Nums']  + t_data['M-Nums'] ), 4)x_list, y1_list, y2_list = [], [], []for _, row in t_data.iterrows():x_list.append(str(row['Year']))if row['Season'] == 'Summer':y1_list.append(row['F-rate'])y2_list.append(None)else:y2_list.append(row['F-rate'])y1_list.append(None)background_color_js = ("new echarts.graphic.LinearGradient(0, 0, 0, 1, ""[{offset: 0, color: '#008B8B'}, {offset: 1, color: '#FF6347'}], false)"
    )line = (Line(init_opts=opts.InitOpts(bg_color=JsCode(background_color_js), width='1000px', height='600px')).add_xaxis(x_list).add_yaxis("夏季奥运会", y1_list, is_smooth=True, is_connect_nones=True,symbol="circle",symbol_size=6,linestyle_opts=opts.LineStyleOpts(color="#fff"),label_opts=opts.LabelOpts(is_show=False, position="top", color="white"),itemstyle_opts=opts.ItemStyleOpts(color="green", border_color="#fff", border_width=3),tooltip_opts=opts.TooltipOpts(is_show=True),).add_yaxis("冬季季奥运会", y2_list, is_smooth=True, is_connect_nones=True, symbol="circle",symbol_size=6,linestyle_opts=opts.LineStyleOpts(color="#FF4500"),label_opts=opts.LabelOpts(is_show=False, position="top", color="white"),itemstyle_opts=opts.ItemStyleOpts(color="red", border_color="#fff", border_width=3),tooltip_opts=opts.TooltipOpts(is_show=True),).set_series_opts(tooltip_opts=opts.TooltipOpts(trigger="item", formatter=JsCode("""function (params) {return params.data[0]+ '年: ' + Number(params.data[1])*100 +'%';}""")),).set_global_opts(title_opts=opts.TitleOpts(title="历届奥运会参赛女性占比趋势",pos_left="center",title_textstyle_opts=opts.TextStyleOpts(color="white", font_size=20),),legend_opts=opts.LegendOpts(is_show=True, pos_top='5%',textstyle_opts=opts.TextStyleOpts(color="white", font_size=12)),xaxis_opts=opts.AxisOpts(type_="value",min_=1904,max_=2016,boundary_gap=False,axislabel_opts=opts.LabelOpts(margin=30, color="#ffffff63",formatter=JsCode("""function (value) {return value+'年';}""")),axisline_opts=opts.AxisLineOpts(is_show=False),axistick_opts=opts.AxisTickOpts(is_show=True,length=25,linestyle_opts=opts.LineStyleOpts(color="#ffffff1f"),),splitline_opts=opts.SplitLineOpts(is_show=True, linestyle_opts=opts.LineStyleOpts(color="#ffffff1f")),),yaxis_opts=opts.AxisOpts(type_="value",position="right",axislabel_opts=opts.LabelOpts(margin=20, color="#ffffff63",formatter=JsCode("""function (value) {return Number(value *100)+'%';}""")),axisline_opts=opts.AxisLineOpts(linestyle_opts=opts.LineStyleOpts(width=2, color="#fff")),axistick_opts=opts.AxisTickOpts(is_show=True,length=15,linestyle_opts=opts.LineStyleOpts(color="#ffffff1f"),),splitline_opts=opts.SplitLineOpts(is_show=True, linestyle_opts=opts.LineStyleOpts(color="#ffffff1f")),),)
    )line.render_notebook()

    39e2e3036f374dac86f779fe9a48b7ee.png

  • 3.3、获得金牌/奖牌比例

  • 整个奥运会(包括夏季,冬季奥运会)历史上参赛人数为134732,获得过金牌的运动员只有10413,占比7.7%;

  • 获得过奖牌(包括金银铜)的运动员有28202人,占比20.93%;

  • total_athlete = len(set(data['Name']))
    medal_athlete = len(set(data['Name'][data['Medal'].isin(['Gold', 'Silver', 'Bronze'])]))
    gold_athlete = len(set(data['Name'][data['Medal']=='Gold']))l1 = Liquid(init_opts=opts.InitOpts(theme='dark', width='1000px', height='800px'))
    l1.add("获得奖牌", [medal_athlete/total_athlete], center=["70%", "50%"],label_opts=opts.LabelOpts(font_size=50,formatter=JsCode("""function (param) {return (Math.floor(param.value * 10000) / 100) + '%';}"""),position="inside",))
    l1.set_global_opts(title_opts=opts.TitleOpts(title="获得过奖牌比例", pos_left='62%', pos_top='8%'))
    l1.set_series_opts(tooltip_opts=opts.TooltipOpts(is_show=False))l2 = Liquid(init_opts=opts.InitOpts(theme='dark', width='1000px', height='800px'))
    l2.add("获得金牌",[gold_athlete/total_athlete],center=["25%", "50%"],label_opts=opts.LabelOpts(font_size=50,formatter=JsCode("""function (param) {return (Math.floor(param.value * 10000) / 100) + '%';}"""),position="inside",),)
    l2.set_global_opts(title_opts=opts.TitleOpts(title="获得过金牌比例", pos_left='17%', pos_top='8%'))
    l2.set_series_opts(tooltip_opts=opts.TooltipOpts(is_show=False))grid = Grid().add(l1, grid_opts=opts.GridOpts()).add(l2, grid_opts=opts.GridOpts())
    grid.render_notebook()
  • d186e21373074b2db506713eb199a03c.png

    运动员平均体质数据

    根据不同的运动项目进行统计

  • 运动员平均身高最高的项目是篮球,女子平均身高达182cm,男子平均身高达到194cm;

  • 在男子项目中,运动员平均体重最大的项目是拔河,平均体重达到96kg(拔河自第七届奥运会后已取消);

  • 运动员平均年龄最大的项目是Art competition(自行百度这奇怪的项目),平均年龄46岁,除此之外便是马术和射击,男子平均年龄分别为34.4岁和34.2岁,女子平均年龄34.22岁和29.12岁;

  • tool_js = """function (param) {return param.data[2] +'<br/>' +'平均体重: '+Number(param.data[0]).toFixed(2)+' kg<br/>'+'平均身高: '+Number(param.data[1]).toFixed(2)+' cm<br/>'+'平均年龄: '+Number(param.data[3]).toFixed(2);}"""background_color_js = ("new echarts.graphic.LinearGradient(1, 0, 0, 1, ""[{offset: 0, color: '#008B8B'}, {offset: 1, color: '#FF6347'}], false)"
    )temp_data = data[data['Sex']=='M'].groupby(['Sport'])['Age', 'Height', 'Weight'].mean().reset_index().dropna(how='any')scatter = (Scatter(init_opts=opts.InitOpts(bg_color=JsCode(background_color_js), width='1000px', height='600px')).add_xaxis(temp_data['Weight'].tolist()).add_yaxis("男性", [[row['Height'], row['Sport'], row['Age']] for _, row in temp_data.iterrows()],# 渐变效果实现部分color=JsCode("""new echarts.graphic.RadialGradient(0.4, 0.3, 1, [{offset: 0,color: 'rgb(129, 227, 238)'}, {offset: 1,color: 'rgb(25, 183, 207)'}])""")).set_series_opts(label_opts=opts.LabelOpts(is_show=False)).set_global_opts(title_opts=opts.TitleOpts(title="各项目运动员平均升高体重年龄",pos_left="center",title_textstyle_opts=opts.TextStyleOpts(color="white", font_size=20)),legend_opts=opts.LegendOpts(is_show=True, pos_top='5%',textstyle_opts=opts.TextStyleOpts(color="white", font_size=12)),tooltip_opts = opts.TooltipOpts(formatter=JsCode(tool_js)),xaxis_opts=opts.AxisOpts(name='体重/kg',# 设置坐标轴为数值类型type_="value", is_scale=True,# 显示分割线axislabel_opts=opts.LabelOpts(margin=30, color="white"),axisline_opts=opts.AxisLineOpts(is_show=True, linestyle_opts=opts.LineStyleOpts(color="#ffffff1f")),axistick_opts=opts.AxisTickOpts(is_show=True, length=25,linestyle_opts=opts.LineStyleOpts(color="#ffffff1f")),splitline_opts=opts.SplitLineOpts(is_show=True, linestyle_opts=opts.LineStyleOpts(color="#ffffff1f"))),yaxis_opts=opts.AxisOpts(name='身高/cm',# 设置坐标轴为数值类型type_="value",# 默认为False表示起始为0is_scale=True,axislabel_opts=opts.LabelOpts(margin=30, color="white"),axisline_opts=opts.AxisLineOpts(is_show=True, linestyle_opts=opts.LineStyleOpts(color="#ffffff1f")),axistick_opts=opts.AxisTickOpts(is_show=True, length=25,linestyle_opts=opts.LineStyleOpts(color="#ffffff1f")),splitline_opts=opts.SplitLineOpts(is_show=True, linestyle_opts=opts.LineStyleOpts(color="#ffffff1f"))),visualmap_opts=opts.VisualMapOpts(is_show=False, type_='size', range_size=[5,50], min_=10, max_=40)))temp_data = data[data['Sex']=='F'].groupby(['Sport'])['Age', 'Height', 'Weight'].mean().reset_index().dropna(how='any')scatter1 = (Scatter().add_xaxis(temp_data['Weight'].tolist()).add_yaxis("女性", [[row['Height'], row['Sport'], row['Age']] for _, row in temp_data.iterrows()],itemstyle_opts=opts.ItemStyleOpts(color=JsCode("""new echarts.graphic.RadialGradient(0.4, 0.3, 1, [{offset: 0,color: 'rgb(251, 118, 123)'}, {offset: 1,color: 'rgb(204, 46, 72)'}])"""))).set_series_opts(label_opts=opts.LabelOpts(is_show=False)))
    scatter.overlap(scatter1)
    scatter.render_notebook() 

    101793bc108b4aea9d44942d90ca74b4.png

    🇨🇳中国奥运会表现

  • CN_data = data[data.region=='China']
    CN_data.head()

    90879b59402b4514a90c04c7e041e5e9.png

    历届奥运会参赛人数 

  • background_color_js = ("new echarts.graphic.LinearGradient(1, 0, 0, 1, ""[{offset: 0, color: '#008B8B'}, {offset: 1, color: '#FF6347'}], false)"
    )athlete = CN_data.groupby(['Year', 'Season'])['Name'].nunique().reset_index()
    athlete.columns = ['Year', 'Season', 'Nums']                                      
    athlete = athlete.sort_values(by="Year" , ascending=False) s_bar = (Bar(init_opts=opts.InitOpts(theme='dark', width='1000px', height='300px')).add_xaxis([row['Year'] for _, row in athlete[athlete.Season=='Summer'].iterrows()]).add_yaxis("参赛人数", [row['Nums'] for _, row in athlete[athlete.Season=='Summer'].iterrows()],category_gap='40%',itemstyle_opts=opts.ItemStyleOpts(border_color='rgb(220,220,220)',color=JsCode("""new echarts.graphic.LinearGradient(0, 0, 0, 1, [{offset: 1,color: '#00BFFF'}, {offset: 0,color: '#32CD32'}])"""))).set_series_opts(label_opts=opts.LabelOpts(is_show=True, position='top',font_style='italic')).set_global_opts(title_opts=opts.TitleOpts(title="中国历年奥运会参赛人数-夏奥会", pos_left='center'),xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=45)),legend_opts=opts.LegendOpts(is_show=False),yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(margin=20, color="#ffffff63")),graphic_opts=[opts.GraphicImage(graphic_item=opts.GraphicItem(id_="logo", right=0, top=0, z=-10, bounding="raw", origin=[75, 75]),graphic_imagestyle_opts=opts.GraphicImageStyleOpts(image="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1586619952245&di=981a36305048f93eec791980acc99cf7&imgtype=0&src=http%3A%2F%2Fimg5.mtime.cn%2Fmg%2F2017%2F01%2F06%2F172210.42721559.jpg",width=1000,height=600,opacity=0.6,),)],))w_bar = (Bar(init_opts=opts.InitOpts(theme='dark',width='1000px', height='300px')).add_xaxis([row['Year'] for _, row in athlete[athlete.Season=='Winter'].iterrows()]).add_yaxis("参赛人数", [row['Nums'] for _, row in athlete[athlete.Season=='Winter'].iterrows()],category_gap='50%',itemstyle_opts=opts.ItemStyleOpts(border_color='rgb(220,220,220)',color=JsCode("""new echarts.graphic.LinearGradient(0, 0, 0, 1, [{offset: 1,color: '#00BFFF'}, {offset: 0.8,color: '#FFC0CB'}, {offset: 0,color: '#40E0D0'}])"""))).set_series_opts(label_opts=opts.LabelOpts(is_show=True, position='top',font_style='italic')).set_global_opts(title_opts=opts.TitleOpts(title="中国历年奥运会参赛人数-冬奥会", pos_left='center'),xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=45)),legend_opts=opts.LegendOpts(is_show=False),yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(margin=20, color="#ffffff63")),graphic_opts=[opts.GraphicImage(graphic_item=opts.GraphicItem(id_="logo", right=0, top=-300, z=-10, bounding="raw", origin=[75, 75]),graphic_imagestyle_opts=opts.GraphicImageStyleOpts(image="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1586619952245&di=981a36305048f93eec791980acc99cf7&imgtype=0&src=http%3A%2F%2Fimg5.mtime.cn%2Fmg%2F2017%2F01%2F06%2F172210.42721559.jpg",width=1000,height=600,opacity=0.6,),)],))page = (Page().add(s_bar,).add(w_bar,)
    )
    page.render_notebook()

    33d7755ce4aa48459507c9dac06a3d52.png

     历届奥运会获得金牌数🏅️

    background_color_js = ("new echarts.graphic.LinearGradient(1, 0, 0, 1, ""[{offset: 0, color: '#008B8B'}, {offset: 1, color: '#FF6347'}], false)"
    )CN_medals = CN_data.groupby(['Year', 'Season', 'Medal'])['Event'].nunique().reset_index()
    CN_medals.columns = ['Year', 'Season', 'Medal', 'Nums']                                      
    CN_medals = CN_medals.sort_values(by="Year" , ascending=False) s_bar = (Bar(init_opts=opts.InitOpts(theme='dark', width='1000px', height='300px')).add_xaxis(sorted(list(set([row['Year'] for _, row in CN_medals[CN_medals.Season=='Summer'].iterrows()])), reverse=True)).add_yaxis("金牌", [row['Nums'] for _, row in CN_medals[(CN_medals.Season=='Summer') & (CN_medals.Medal=='Gold')].iterrows()],category_gap='20%',itemstyle_opts=opts.ItemStyleOpts(border_color='rgb(220,220,220)',color=JsCode("""new echarts.graphic.LinearGradient(0, 0, 0, 1, [{offset: 0,color: '#FFD700'}, {offset: 1,color: '#FFFFF0'}])"""))).add_yaxis("银牌", [row['Nums'] for _, row in CN_medals[(CN_medals.Season=='Summer') & (CN_medals.Medal=='Silver')].iterrows()],category_gap='20%',itemstyle_opts=opts.ItemStyleOpts(border_color='rgb(220,220,220)',color=JsCode("""new echarts.graphic.LinearGradient(0, 0, 0, 1, [{offset: 0,color: '#C0C0C0'}, {offset: 1,color: '#FFFFF0'}])"""))).add_yaxis("铜牌", [row['Nums'] for _, row in CN_medals[(CN_medals.Season=='Summer') & (CN_medals.Medal=='Bronze')].iterrows()],category_gap='20%',itemstyle_opts=opts.ItemStyleOpts(border_color='rgb(220,220,220)',color=JsCode("""new echarts.graphic.LinearGradient(0, 0, 0, 1, [{offset: 0,color: '#DAA520'}, {offset: 1,color: '#FFFFF0'}])"""))).set_series_opts(label_opts=opts.LabelOpts(is_show=True, position='top',font_style='italic')).set_global_opts(title_opts=opts.TitleOpts(title="中国历年奥运会获得奖牌数数-夏奥会", pos_left='center'),xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=45)),legend_opts=opts.LegendOpts(is_show=False),yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(margin=20, color="#ffffff63")),graphic_opts=[opts.GraphicImage(graphic_item=opts.GraphicItem(id_="logo", right=0, top=0, z=-10, bounding="raw", origin=[75, 75]),graphic_imagestyle_opts=opts.GraphicImageStyleOpts(image="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1586619952245&di=981a36305048f93eec791980acc99cf7&imgtype=0&src=http%3A%2F%2Fimg5.mtime.cn%2Fmg%2F2017%2F01%2F06%2F172210.42721559.jpg",width=1000,height=600,opacity=0.6,),)],))w_bar = (Bar(init_opts=opts.InitOpts(theme='dark', width='1000px', height='300px')).add_xaxis(sorted(list(set([row['Year'] for _, row in CN_medals[CN_medals.Season=='Winter'].iterrows()])), reverse=True)).add_yaxis("金牌", [row['Nums'] for _, row in CN_medals[(CN_medals.Season=='Winter') & (CN_medals.Medal=='Gold')].iterrows()],category_gap='20%',itemstyle_opts=opts.ItemStyleOpts(border_color='rgb(220,220,220)',color=JsCode("""new echarts.graphic.LinearGradient(0, 0, 0, 1, [{offset: 0,color: '#FFD700'}, {offset: 1,color: '#FFFFF0'}])"""))).add_yaxis("银牌", [row['Nums'] for _, row in CN_medals[(CN_medals.Season=='Winter') & (CN_medals.Medal=='Silver')].iterrows()],category_gap='20%',itemstyle_opts=opts.ItemStyleOpts(border_color='rgb(220,220,220)',color=JsCode("""new echarts.graphic.LinearGradient(0, 0, 0, 1, [{offset: 0,color: '#C0C0C0'}, {offset: 1,color: '#FFFFF0'}])"""))).add_yaxis("铜牌", [row['Nums'] for _, row in CN_medals[(CN_medals.Season=='Winter') & (CN_medals.Medal=='Bronze')].iterrows()],category_gap='20%',itemstyle_opts=opts.ItemStyleOpts(border_color='rgb(220,220,220)',color=JsCode("""new echarts.graphic.LinearGradient(0, 0, 0, 1, [{offset: 0,color: '#DAA520'}, {offset: 1,color: '#FFFFF0'}])"""))).set_series_opts(label_opts=opts.LabelOpts(is_show=True, position='top',font_style='italic')).set_global_opts(title_opts=opts.TitleOpts(title="中国历年奥运会获得奖牌数-冬奥会", pos_left='center'),xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=45)),legend_opts=opts.LegendOpts(is_show=False),yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(margin=20, color="#ffffff63")),graphic_opts=[opts.GraphicImage(graphic_item=opts.GraphicItem(id_="logo", right=0, top=-300, z=-10, bounding="raw", origin=[75, 75]),graphic_imagestyle_opts=opts.GraphicImageStyleOpts(image="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1586619952245&di=981a36305048f93eec791980acc99cf7&imgtype=0&src=http%3A%2F%2Fimg5.mtime.cn%2Fmg%2F2017%2F01%2F06%2F172210.42721559.jpg",width=1000,height=600,opacity=0.6,),)],))page = (Page().add(s_bar,).add(w_bar,)
    )
    page.render_notebook()

    c9bdbc3ca17e479eb1b86f386e0c873d.png

    优势项目

    跳水,体操,射击,举重,乒乓球,羽毛球

  • background_color_js = ("new echarts.graphic.LinearGradient(1, 0, 0, 1, ""[{offset: 0.5, color: '#FFC0CB'}, {offset: 1, color: '#F0FFFF'}, {offset: 0, color: '#EE82EE'}], false)"
    )CN_events = CN_data[CN_data.Medal=='Gold'].groupby(['Year', 'Sport'])['Event'].nunique().reset_index()
    CN_events = CN_events.groupby(['Sport'])['Event'].sum().reset_index()
    CN_events.columns = ['Sport', 'Nums']                                      data_pair = [(row['Sport'], row['Nums']) for _, row in CN_events.iterrows()]wc = (WordCloud(init_opts=opts.InitOpts(bg_color=JsCode(background_color_js), width='1000px', height='600px')).add("", data_pair,word_size_range=[30, 80]).set_global_opts(title_opts=opts.TitleOpts(title="中国获得过金牌运动项目",pos_left="center",title_textstyle_opts=opts.TextStyleOpts(color="white", font_size=20)))
    )wc.render_notebook()

    6fff6492a9604ed990043b59f19749e6.png

     🇺🇸美国奥运会表现

  • USA_data = data[data.region=='USA']
    USA_data.head()

    54b3cff1361c486babc81171e4e2b177.png

    历届奥运会参加人数

  • background_color_js = ("new echarts.graphic.LinearGradient(1, 0, 0, 1, ""[{offset: 0, color: '#008B8B'}, {offset: 1, color: '#FF6347'}], false)"
    )athlete = USA_data.groupby(['Year', 'Season'])['Name'].nunique().reset_index()
    athlete.columns = ['Year', 'Season', 'Nums']                                      
    athlete = athlete.sort_values(by="Year" , ascending=False) s_bar = (Bar(init_opts=opts.InitOpts(theme='dark', width='1000px', height='300px')).add_xaxis([row['Year'] for _, row in athlete[athlete.Season=='Summer'].iterrows()]).add_yaxis("参赛人数", [row['Nums'] for _, row in athlete[athlete.Season=='Summer'].iterrows()],category_gap='40%',itemstyle_opts=opts.ItemStyleOpts(border_color='rgb(220,220,220)',color=JsCode("""new echarts.graphic.LinearGradient(0, 0, 0, 1, [{offset: 1,color: '#00BFFF'}, {offset: 0,color: '#32CD32'}])"""))).set_series_opts(label_opts=opts.LabelOpts(is_show=True, position='top',font_style='italic')).set_global_opts(title_opts=opts.TitleOpts(title="美国历年奥运会参赛人数-夏奥会", pos_left='center'),xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=45)),legend_opts=opts.LegendOpts(is_show=False),yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(margin=20, color="#ffffff63")),graphic_opts=[opts.GraphicImage(graphic_item=opts.GraphicItem(id_="logo", right=0, top=0, z=-10, bounding="raw", origin=[75, 75]),graphic_imagestyle_opts=opts.GraphicImageStyleOpts(image="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1586619952245&di=981a36305048f93eec791980acc99cf7&imgtype=0&src=http%3A%2F%2Fimg5.mtime.cn%2Fmg%2F2017%2F01%2F06%2F172210.42721559.jpg",width=1000,height=600,opacity=0.6,),)],))w_bar = (Bar(init_opts=opts.InitOpts(theme='dark',width='1000px', height='300px')).add_xaxis([row['Year'] for _, row in athlete[athlete.Season=='Winter'].iterrows()]).add_yaxis("参赛人数", [row['Nums'] for _, row in athlete[athlete.Season=='Winter'].iterrows()],category_gap='50%',itemstyle_opts=opts.ItemStyleOpts(border_color='rgb(220,220,220)',color=JsCode("""new echarts.graphic.LinearGradient(0, 0, 0, 1, [{offset: 1,color: '#00BFFF'}, {offset: 0.8,color: '#FFC0CB'}, {offset: 0,color: '#40E0D0'}])"""))).set_series_opts(label_opts=opts.LabelOpts(is_show=True, position='top',font_style='italic')).set_global_opts(title_opts=opts.TitleOpts(title="美国历年奥运会参赛人数-冬奥会", pos_left='center'),xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=45)),legend_opts=opts.LegendOpts(is_show=False),yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(margin=20, color="#ffffff63")),graphic_opts=[opts.GraphicImage(graphic_item=opts.GraphicItem(id_="logo", right=0, top=-300, z=-10, bounding="raw", origin=[75, 75]),graphic_imagestyle_opts=opts.GraphicImageStyleOpts(image="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1586619952245&di=981a36305048f93eec791980acc99cf7&imgtype=0&src=http%3A%2F%2Fimg5.mtime.cn%2Fmg%2F2017%2F01%2F06%2F172210.42721559.jpg",width=1000,height=600,opacity=0.6,),)],))page = (Page().add(s_bar,).add(w_bar,)
    )
    page.render_notebook()

    c61289d1549a44688aa1cbf0255a597e.png

    历届奥运会获得奖牌数

  • background_color_js = ("new echarts.graphic.LinearGradient(1, 0, 0, 1, ""[{offset: 0, color: '#008B8B'}, {offset: 1, color: '#FF6347'}], false)"
    )medals = USA_data.groupby(['Year', 'Season', 'Medal'])['Event'].nunique().reset_index()
    medals.columns = ['Year', 'Season', 'Medal', 'Nums']                                      
    medals = medals.sort_values(by="Year" , ascending=False) s_bar = (Bar(init_opts=opts.InitOpts(theme='dark', width='1000px', height='300px')).add_xaxis(sorted(list(set([row['Year'] for _, row in medals[medals.Season=='Summer'].iterrows()])), reverse=True)).add_yaxis("金牌", [row['Nums'] for _, row in medals[(medals.Season=='Summer') & (medals.Medal=='Gold')].iterrows()],category_gap='20%',itemstyle_opts=opts.ItemStyleOpts(border_color='rgb(220,220,220)',color=JsCode("""new echarts.graphic.LinearGradient(0, 0, 0, 1, [{offset: 0,color: '#FFD700'}, {offset: 1,color: '#FFFFF0'}])"""))).add_yaxis("银牌", [row['Nums'] for _, row in medals[(medals.Season=='Summer') & (medals.Medal=='Silver')].iterrows()],category_gap='20%',itemstyle_opts=opts.ItemStyleOpts(border_color='rgb(220,220,220)',color=JsCode("""new echarts.graphic.LinearGradient(0, 0, 0, 1, [{offset: 0,color: '#C0C0C0'}, {offset: 1,color: '#FFFFF0'}])"""))).add_yaxis("铜牌", [row['Nums'] for _, row in medals[(medals.Season=='Summer') & (medals.Medal=='Bronze')].iterrows()],category_gap='20%',itemstyle_opts=opts.ItemStyleOpts(border_color='rgb(220,220,220)',color=JsCode("""new echarts.graphic.LinearGradient(0, 0, 0, 1, [{offset: 0,color: '#DAA520'}, {offset: 1,color: '#FFFFF0'}])"""))).set_series_opts(label_opts=opts.LabelOpts(is_show=True, position='top',font_style='italic')).set_global_opts(title_opts=opts.TitleOpts(title="美国历年奥运会获得奖牌数数-夏奥会", pos_left='center'),xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=45)),legend_opts=opts.LegendOpts(is_show=False),yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(margin=20, color="#ffffff63")),graphic_opts=[opts.GraphicImage(graphic_item=opts.GraphicItem(id_="logo", right=0, top=0, z=-10, bounding="raw", origin=[75, 75]),graphic_imagestyle_opts=opts.GraphicImageStyleOpts(image="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1586619952245&di=981a36305048f93eec791980acc99cf7&imgtype=0&src=http%3A%2F%2Fimg5.mtime.cn%2Fmg%2F2017%2F01%2F06%2F172210.42721559.jpg",width=1000,height=600,opacity=0.6,),)],))w_bar = (Bar(init_opts=opts.InitOpts(theme='dark', width='1000px', height='300px')).add_xaxis(sorted(list(set([row['Year'] for _, row in medals[medals.Season=='Winter'].iterrows()])), reverse=True)).add_yaxis("金牌", [row['Nums'] for _, row in medals[(medals.Season=='Winter') & (medals.Medal=='Gold')].iterrows()],category_gap='20%',itemstyle_opts=opts.ItemStyleOpts(border_color='rgb(220,220,220)',color=JsCode("""new echarts.graphic.LinearGradient(0, 0, 0, 1, [{offset: 0,color: '#FFD700'}, {offset: 1,color: '#FFFFF0'}])"""))).add_yaxis("银牌", [row['Nums'] for _, row in medals[(medals.Season=='Winter') & (medals.Medal=='Silver')].iterrows()],category_gap='20%',itemstyle_opts=opts.ItemStyleOpts(border_color='rgb(220,220,220)',color=JsCode("""new echarts.graphic.LinearGradient(0, 0, 0, 1, [{offset: 0,color: '#C0C0C0'}, {offset: 1,color: '#FFFFF0'}])"""))).add_yaxis("铜牌", [row['Nums'] for _, row in medals[(medals.Season=='Winter') & (medals.Medal=='Bronze')].iterrows()],category_gap='20%',itemstyle_opts=opts.ItemStyleOpts(border_color='rgb(220,220,220)',color=JsCode("""new echarts.graphic.LinearGradient(0, 0, 0, 1, [{offset: 0,color: '#DAA520'}, {offset: 1,color: '#FFFFF0'}])"""))).set_series_opts(label_opts=opts.LabelOpts(is_show=True, position='top',font_style='italic')).set_global_opts(title_opts=opts.TitleOpts(title="美国历年奥运会获得奖牌数-冬奥会", pos_left='center'),xaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(rotate=45)),legend_opts=opts.LegendOpts(is_show=False),yaxis_opts=opts.AxisOpts(axislabel_opts=opts.LabelOpts(margin=20, color="#ffffff63")),graphic_opts=[opts.GraphicImage(graphic_item=opts.GraphicItem(id_="logo", right=0, top=-300, z=-10, bounding="raw", origin=[75, 75]),graphic_imagestyle_opts=opts.GraphicImageStyleOpts(image="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1586619952245&di=981a36305048f93eec791980acc99cf7&imgtype=0&src=http%3A%2F%2Fimg5.mtime.cn%2Fmg%2F2017%2F01%2F06%2F172210.42721559.jpg",width=1000,height=600,opacity=0.6,),)],))page = (Page().add(s_bar,).add(w_bar,)
    )
    page.render_notebook()

    优势项目

    田径,游泳

  • background_color_js = ("new echarts.graphic.LinearGradient(1, 0, 0, 1, ""[{offset: 0.5, color: '#FFC0CB'}, {offset: 1, color: '#F0FFFF'}, {offset: 0, color: '#EE82EE'}], false)"
    )events = USA_data[USA_data.Medal=='Gold'].groupby(['Year', 'Sport'])['Event'].nunique().reset_index()
    events = events.groupby(['Sport'])['Event'].sum().reset_index()
    events.columns = ['Sport', 'Nums']                                      data_pair = [(row['Sport'], row['Nums']) for _, row in events.iterrows()]wc = (WordCloud(init_opts=opts.InitOpts(bg_color=JsCode(background_color_js), width='1000px', height='600px')).add("", data_pair,word_size_range=[30, 80]).set_global_opts(title_opts=opts.TitleOpts(title="美国获得过金牌运动项目",pos_left="center",title_textstyle_opts=opts.TextStyleOpts(color="white", font_size=20)))
    )wc.render_notebook()

    79c6b08b214e4c38ae048af21e37d545.png

    被单个国家统治的奥运会项目

    很多运动长期以来一直是被某个国家统治,譬如我们熟知的中国🇨🇳的乒乓球,美国🇺🇸的篮球;

    此次筛选了近5届奥运会(2000年悉尼奥运会之后)上累计产生10枚金牌以上且存在单个国家「夺金率」超过50%的项目;

  • 俄罗斯🇷🇺包揽了2000年以后花样游泳 & 艺术体操两个项目上所有的20枚金牌;

  • 中国🇨🇳在乒乓球项目上获得了2000年之后10枚金牌中的9枚,丢失金牌的一次是在04年雅典奥运会男单项目上;

  • 美国🇺🇸在篮球项目上同样获得了过去10枚金牌中的9枚,丢失金牌的一次同样在04年,男篮半决赛中输给了阿根廷,最终获得铜牌;

  • 跳水项目上,中国🇨🇳获得了过去40枚金牌中的31枚,梦之队名不虚传;

  • 射箭项目上,韩国🇰🇷获得了过去20枚金牌中的15枚;

  • 羽毛球项目上,中国🇨🇳获得了过去25枚金牌中的17枚;

  • 沙滩排球项目上,美国🇺🇸获得了过去10枚金牌中的5枚;

  • f1 = lambda x:max(x['Event']) / sum(x['Event'])
    f2 = lambda x: x.sort_values('Event', ascending=False).head(1)t_data = data[(data.Medal=='Gold') & (data.Year>=2000) &(data.Season=='Summer')].groupby(['Year', 'Sport', 'region'])['Event'].nunique().reset_index()
    t_data = t_data.groupby(['Sport', 'region'])['Event'].sum().reset_index()
    t1 = t_data.groupby(['Sport']).apply(f2).reset_index(drop=True)
    t2 = t_data.groupby(['Sport'])['Event'].sum().reset_index()
    t_data = pd.merge(t1, t2, on='Sport', how='inner')
    t_data['gold_rate'] = t_data.Event_x/ t_data.Event_y
    t_data = t_data.sort_values('gold_rate', ascending=False).reset_index(drop=True)t_data = t_data[(t_data.gold_rate>=0.5) & (t_data.Event_y>=10)]background_color_js = ("new echarts.graphic.LinearGradient(1, 0, 0, 1, ""[{offset: 0, color: '#008B8B'}, {offset: 1, color: '#FF6347'}], false)"
    )fn = """function(params) {if(params.name == '其他国家')return '\\n\\n\\n' + params.name + ' : ' + params.value ;return params.seriesName+ '\\n' + params.name + ' : ' + params.value;}"""def new_label_opts():return opts.LabelOpts(formatter=JsCode(fn), position="center")pie = Pie(init_opts=opts.InitOpts(theme='dark', width='1000px', height='1000px'))
    idx = 0for _, row in t_data.iterrows():if idx % 2 == 0:x = 30y = int(idx/2) * 22 + 18else:x = 70y = int(idx/2) * 22 + 18idx += 1pos_x = str(x)+'%'pos_y = str(y)+'%'pie.add(row['Sport'],[[row['region'], row['Event_x']], ['其他国家', row['Event_y']-row['Event_x']]],center=[pos_x, pos_y],radius=[70, 100],label_opts=new_label_opts(),)pie.set_global_opts(title_opts=opts.TitleOpts(title="被单个国家统治的项目",subtitle='统计周期:2000年悉尼奥运会起',pos_left="center",title_textstyle_opts=opts.TextStyleOpts(color="white", font_size=20)),legend_opts=opts.LegendOpts(is_show=False),)pie.render_notebook()

     5cf8144ea0ce498092adc52f0c7d197a.png

    2020东京奥运会金牌分布🏅️ ​​​​​​​

  • 数据准备
  • import requests
    import pandas as pddata_url = 'https://app-sc.miguvideo.com/vms-livedata/olympic\
    -medal/total-table/15/110000004609'
    # 请求数据
    data = requests.get(data_url).json()
    df = pd.DataFrame()for item in data['body']['allMedalData']:df = df.append([[item['countryName'],item['countryId'],item['rank'],item['goldMedalNum'],item['silverMedalNum'],item['bronzeMedalNum'],item['totalMedalNum']]])
    # 修改列名
    df.columns = ['国家', '国家id', '排名', '金牌', '银牌', '铜牌', '奖牌']
    # 重置索引
    df.reset_index(drop=True, inplace=True)
    df.head()

    37230312706d4fa2a7195df443a007ac.png

    data_url = 'https://app-sc.miguvideo.com/\
    vms-livedata/olympic-medal/detail-total/15/110000004609'data = requests.get(data_url).json()
    detail_df = pd.DataFrame()
    # 请求数据
    for item in data['body']['medalTableDetail']:detail_df = detail_df.append([[item['awardTime'],item['medalType'],item['sportsName'],item['countryId'],item['bigItemName']]])
    # 修改列名
    detail_df.columns = ['获奖时间', '奖牌类型', '运动员', '国家id', '运动类别']
    # 重置索引
    detail_df.reset_index(drop=True, inplace=True)
    detail_df.head()

    44664a420f254552bf4c8295d3e2642d.png 

    detail_df.loc[detail_df['奖牌类型'] == 1, '奖牌类型'] = '金牌'
    detail_df.loc[detail_df['奖牌类型'] == 2, '奖牌类型'] = '银牌'
    detail_df.loc[detail_df['奖牌类型'] == 3, '奖牌类型'] = '铜牌'courtry_df = df.loc[:, ['国家', '国家id']]
    detail_df = pd.merge(detail_df, courtry_df, on='国家id', how = "inner")
    detail_df.head()

     741e5a754ad843a8a34f355676699d5d.png

    df.to_csv('东京奥运会国家排名.csv', index=False)
    detail_df.to_csv('东京奥运会获奖详情.csv', index=False)

    分布图展示

  • data = [("United States", 113), ("China", 88), ("Japan", 58), ("United Kingdom", 65), ("United Kingdom", 65), ("Russia", 71),("Australia", 46),  ("Netherlands", 36),  ("France", 33),  ("Germany", 37),  ("Italy", 40),  ("Canada", 24),("Brazil", 21),  ("New Zealand", 20),  ("Cuba", 15),  ("Hungary", 20),  ("South Korea", 20),  ("Poland", 14),("Czech Republic", 11),  ("Kenya", 10),  ("Norway", 8),  ("Jamaica", 9),  ("Spain", 17),  ("Sweden", 9),("Switzerland", 13),  ("Denmark", 11),  ("Croatia", 8),  ("Iran", 7),  ("Serbia", 9),  ("Belgium", 7),("Bulgaria", 6),  ("Slovenia", 5),  ("Uzbekistan", 5),  ("Georgia", 8),  ("China Taibei", 12),  ("Turkey", 13),("Greece", 4),  ("Uganda", 4),  ("Ecuador", 3),  ("Ireland", 4),  ("Israel", 4),  ("Qatar", 3),("Bahamas", 2),  ("kosovo", 2),  ("Ukraine", 19),  ("Belarus", 7),  ("Romania", 4),  ("Venezuela", 4),("India", 7),  ("Hong Kong China", 6),  (" Philippine Islands", 4),  ("Slovakia", 4),  ("South Africa", 3),  ("Austria", 7),("Egypt", 6),  ("Indonesia", 5),  ("Ethiopia", 4),  ("Portugal", 4),  ("Tunisia", 2),  ("Estonia", 2),  ("Fiji", 2),  ("Latvia", 2),  ("Thailand", 2),  ("Bermuda", 1),  ("Morocco", 1),  ("Puerto Rico", 1),("Columbia", 5),  ("Azerbaijan", 7),  ("Dominican", 5),  ("Armenian", 4),  ("Kyrgyzstan", 3),  ("Mongolia", 4),("Argentina", 3),  ("San Marino", 3),  ("Jordan", 2),  ("Malaysia", 2),  ("Nigeria", 2),  ("Bahrain", 1),("Lithuania", 1),  ("Namibia", 1),  ("Northern Macedonia", 1),  ("Saudi Arabia", 1),  ("Turkmenistan", 1),  ("Kazakhstan", 8),("Mexico",4 ),  ("Finland", 2),  ("Botswana", 1),  ("burkina faso", 1),  ("Ghana", 1),  ("Grenada", 1),("Côte d'Ivoire", 1),  ("Kuwait", 1),  ("Moldova", 1),  ("Syria", 1)]
    charts = (Map().add("奖牌",data,"world",is_map_symbol_show=False).set_series_opts(label_opts=opts.LabelOpts(is_show=False)).set_global_opts(title_opts=opts.TitleOpts(title="2020东京奥运会各国金牌分布图"),visualmap_opts=opts.VisualMapOpts(max_=120,is_piecewise=True,split_number=3)))
    charts.render_notebook()

    812a5fa76ec2410ca606ee44235aa3ff.png 

  •  

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/69339.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

数据分析案例-往届世界杯数据可视化

目录 1.引言 2.项目简介 2.1数据集介绍 2.2技术工具 3.数据可视化 3.1往届世界杯获奖国家TOP5 3.2往届世界杯比赛数据情况 3.3往届世界杯观众人数情况 3.4往届世界杯主办方情况 3.5往届世界杯冠军队情况 1.引言 足球是世界上非常受欢迎的运动之一&#xff0c;在全球…

还在开发短信验证码登录?试试(本机号码一键登录)

点击上方蓝字关注我们 技术总监面试&#xff0c;提问&#xff1a;Redis热点key解决方案 一、 关于秒验&#xff08;一键登录&#xff09;基本原理 秒验&#xff08;一键登录&#xff09;产品整合了三大运营商特有的数据网关认证能力&#xff0c;升级短信验证码体验&#xff0c;…

模拟验证码发送

目录 一&#xff0e;模拟验证码发送 1.输入手机号&#xff0c;点击发送随机生成6位数字码&#xff0c; 2.两分钟内有效&#xff0c;把验证码放入Redis里面&#xff0c;设置过期时间为120秒 3.判断验证码是否符合一致&#xff0c;从Redis获取验证码和输入的验证码进行比较 4…

打造抖音爆款脚本文案,让你分分钟钟上热门涨粉。

要想在抖音里面占据一席之地,运营者必须具备基本的短视频脚本创作能力。 有的人,为了一个创意能想上一天;而有的人,通过一些技巧,延伸出无数个好的想法。 那么优质的短视频脚本的创意又是从何而来的呢?猫哥告诉你短视频脚本文案要怎么写。 如果你本身是做文案工作的,…

1062 Talent and Virtue (25 分)排序(水题)

题目 About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about people’s talent and virtue. According to his theory, a man being outstanding in both talent and virtue must be a “sage&#xff08;圣人&#xff09;”…

PAT甲级 1011 World Cup Betting (20 分) 题解

\quad 这个题难在题意理解上面&#xff0c;说白了就是给你九个数&#xff0c;三个一组&#xff0c;找出一组中最大的数字并记录下这个数所属类别(W,T,L)。一行是一组。最后把每个组最大的数乘起来&#xff0c;乘0.65&#xff0c;再减去1&#xff0c;最后将所得结果乘2输出。即 …

day8 足球运动员分析

足球运动员分析 背景信息 当前&#xff0c;足球运动是最受欢迎的运动之一&#xff08;也可以说没有之一&#xff09;。 任务说明 我们的任务&#xff0c;就是在众多的足球运动员中&#xff0c;发现统计一些关于足球运动员的共性&#xff0c;或某些潜在的规律。 数据集描述…

The Most Common Habits from more than 200 English Papers written by Graduate Chinese Students

目录 定冠词/不定冠词的使用 a an the句子不要太长在段落开始直接陈述中心思想不要在段落开头直接使用时间状语从句将重要的主语放在最最开始以表示强调which/that所引导的定语从句的指代不明Respectively的使用有关in this paper/study数字‘Figure’ and ‘Table’‘such as’…

GPT系列的数据集之谜

文&#xff5c;Alan D. Thompson 源&#xff5c;OneFlow 译&#xff5c;杨婷、徐佳渝、贾川 半个月以来&#xff0c;ChatGPT这把火越烧越旺。国内很多大厂相继声称要做中文版ChatGPT&#xff0c;还公布了上线时间表&#xff0c;不少科技圈已功成名就的大佬也按捺不住&#xf…

Claude 2 解读 ChatGPT 4 的技术秘密:细节:参数数量、架构、基础设施、训练数据集、成本...

“ 解密 ChatGPT 4的模型架构、训练基础设施、推理基础设施、参数计数、训练数据集组成、令牌计数、层数、并行策略、多模态视觉适应、不同工程权衡背后的思维过程、独特的实施技术。” ‍‍‍‍ 01 — 最近偶然看到一份文档《GPT-4 Architecture, Infrastructure, Training Da…

Window的创建

Window的创建 上一篇说到了Window和WindowManager的关系并且讲述了WindowManager如何添加Window与Window内部的三个方法的实现 这篇主要讲几个常见的Window的创建比如Activity,Dialog和Toast 其中Activity属于应用Window Dialog属于子Window Toast属于系统Window z-order…

密码验证 长度八位包含字母数字特殊字符

View Code 1 #region 密码验证2 if (tbPassword.Text "")3 {4 CommonFunction.ShowMessage(this.Page, "密码不能为空");5 return;6 }7 …

smart计算机英语作文,关于科技的英语作文(精选5篇)

关于科技的英语作文(精选5篇) 在平平淡淡的日常中&#xff0c;大家都跟作文打过交道吧&#xff0c;写作文可以锻炼我们的独处习惯&#xff0c;让自己的心静下来&#xff0c;思考自己未来的方向。一篇什么样的作文才能称之为优秀作文呢&#xff1f;下面是小编精心整理的关于科技…

华为鸿蒙的科技话题作文800字,科技的发展作文800字4篇

科技的发展作文800字4篇 科技改变生活&#xff0c;可以说没有科技的高速发展就没有今天的我们。那么以下是小编为大家整理的科技的发展作文800字&#xff0c;欢迎大家阅读&#xff01; 科技的发展作文800字(一) 随着科学技术的高度发展&#xff0c;科技是利是弊成了人们热议的话…

计算机未来的发展英语作文,关于科技发展英语作文(通用10篇)

关于科技发展英语作文(通用10篇) 在平平淡淡的学习、工作、生活中&#xff0c;大家总免不了要接触或使用作文吧&#xff0c;写作文可以锻炼我们的独处习惯&#xff0c;让自己的心静下来&#xff0c;思考自己未来的方向。那么一般作文是怎么写的呢&#xff1f;下面是小编为大家整…

计算机技术发展作文,【推荐】科技发展作文三篇

【推荐】科技发展作文三篇 在日复一日的学习、工作或生活中&#xff0c;大家都写过作文&#xff0c;肯定对各类作文都很熟悉吧&#xff0c;作文是经过人的思想考虑和语言组织&#xff0c;通过文字来表达一个主题意义的记叙方法。相信许多人会觉得作文很难写吧&#xff0c;下面是…

Android混合开发快速上手掌握

目录 一 混合开发简介 二 Android-Js互调 2.1 准备自己的html文件 2.2 WebView控件的准备设置 2.3 Android调用Js代码 2.4 Js调用Android方法和传参数 三 常用的几个方法和注意点 3.1 WebViewClient中的shouldOverrideUrlLoading拦截url 3.2 WebViewClient中的onPageS…

安卓开发快速集成即时通讯聊天,只需几行代码轻松实现

信贸通即时通讯系统&#xff0c;一款跨平台可定制的 P2P 即时通信系统&#xff0c;为电子商务网站及各行业门户网站和企事业单位提供“一站式”定制解决方案&#xff0c;打造一个稳定&#xff0c;安全&#xff0c;高效&#xff0c;可扩展的即时通信系统&#xff0c;支持在线聊天…

IM即时通讯聊天,5分钟显示一次时间。JS

想在聊天界面想做个和微信一样的时间显示 达到下图这种效果 百度了一下&#xff0c;发现都是有点不全的&#xff0c;把网上的合并了一下组成下方的js文件 记录一下 1.建议新建一个JS文件 common.js 1.第一个方法是把时间戳转成具体时间日期 /** * 对Date的扩展&#xff0c;将…

GPT-4 Copilot X震撼来袭!写代码效率10倍提升,码农遭降维打击

因公众号更改推送规则&#xff0c;请点“在看”并加“星标”第一时间获取精彩技术分享 点击关注#互联网架构师公众号&#xff0c;领取架构师全套资料 都在这里 0、2T架构师学习资料干货分 上一篇&#xff1a;2T架构师学习资料干货分享 大家好&#xff0c;我是互联网架构师&…