You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Python Pandas删除表格非冠军行 统计球队夺冠次数并可视化

你现有代码存在1处核心逻辑错误:你已经将筛选后Position为1的夺冠数据存入了team_win变量,但后续分组统计时误用了原始全量数据gry,会导致最终统计的是所有队伍的参赛次数,而非夺冠次数。

修正后的可运行代码如下:

import pandas as pd
import plotly.express as px

# 筛选夺冠行数据
team_win = cons[cons['Position'] == '1']

# 统计各队夺冠次数,简化冗余处理步骤
team_win_c = team_win.groupby('Team')['Team'].count().reset_index(name='Wins')

# 按夺冠次数降序排序,取Top10
team_win_c = team_win_c.sort_values(by='Wins', ascending=False).head(10)

# 绘制柱状图
fig = px.bar(team_win_c, x='Team', y='Wins', color='Wins', width=750, height=500)
fig.update_layout(title={'text': '夺冠次数最多的10支球队','y':0.95,'x':0.5})
fig.show()

如需调整柱状图的排序规则、配色、尺寸等效果,直接修改绘图函数的对应参数即可。

内容的提问来源于stack exchange,提问作者MatJablo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.19 16:45:02