Creating Knock Out Tournament Matches In 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',
Solution 1:
please try,
df1=pd.DataFrame()
df1['Team1']=df.loc[0::2,'winner'].values
df1['Team2']=df.loc[1::2,'winner'].values
Solution 2:
You can use the list slicing, some_list[start:stop:step]
winners_list = df['winner'].tolist()
df1 = pd.DataFrame()
df1['Team1'] = winners_list[0::2]
df1['Team2'] = winners_list[1::2]
- Take the winners from
df
as list (you can also take aspandas.core.series.Series
and use slicing but when you use it to create a data frame you will face issues because of indexing) - Create a new dataframe and take the even indexed elements from winners list as Team1
- Take the odd indexed elements from the winners list as Team2.
Post a Comment for "Creating Knock Out Tournament Matches In Pandas"