在 pandas 中创建淘汰赛比赛 [英] Creating knock out tournament matches in Pandas

查看:110
本文介绍了在 pandas 中创建淘汰赛比赛的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为足球比赛创建淘汰赛。

I am creating knocked tournament matches for soccer games.

df = pd.DataFrame()
df['Team1']   = ['A','B','C','D','E','F']
df['Score1']  = [1,2,3,1,2,4]
df['Team2']   = ['U','V','W','X','Y','Z']
df['Score2']  = [2,1,2,2,3,3]
df['Match']   = df['Team1']  + ' Vs '+ df['Team2']
df['Match_no']= [1,2,3,4,5,6]
winner = df.Score1>df.Score2
df['winner']  = np.where(winner,df['Team1'],df['Team2'])
df ['Stage']  ='R16

可以说,上面的代码用于淘汰赛阶段。通过运行上述代码,我们为每场比赛赢得了一名(6名)。每个比赛都编号为1,2,3,依此类推。

Let's say, the above code is for knocked out stage. By running above code, we have a winner for each match ( 6 winners). Each match is numbered as 1,2,3 and so on.

我要做的是为下一阶段的比赛创建另一个日期框架。
在下一阶段,我们将进行3场比赛。
在这些比赛中,将出现奇数比赛号码和偶数比赛号码的获胜者(即U vs B,C vs X,Y vs F)
我只需要球队进入新的数据框即可。
谁能建议我如何解散那些球队?

What I want to do is to create another date frame for next stage of tournament. In next stage , we will have 3 matches. In these matches, winner from odd match number and even match number will play (i.e. U vs B,C vs X, Y vs F) I just need teams to be in new dataframe. Can anyone advise me how to extract those teams?

谢谢

Zep

推荐答案

请尝试,

df1=pd.DataFrame()
df1['Team1']=df.loc[0::2,'winner'].values
df1['Team2']=df.loc[1::2,'winner'].values

这篇关于在 pandas 中创建淘汰赛比赛的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆