jeudi 18 avril 2019

I want create a list from values in a dataset based on a specific condition

I am working with a Dataset that contains the information of every March Madness game since 1985. I want to know which teams have won it all and how many times each.

I masked the main dataset and created a new one containing only information about the championship game. Now I am trying to create a loop that compares the scores from both teams that played in the championship game, detects the winner and adds that team to a list. This is how the dataset looks like: https://imgur.com/tXhPYSm

tourney = pd.read_csv('ncaa.csv')

champions = tourney.loc[tourney['Region Name'] == "Championship", ['Year','Seed','Score','Team','Team.1','Score.1','Seed.1']]

list_champs = []

for i in champions:
    if champions['Score'] > champions['Score.1']:
        list_champs.append(i['Team'])
    else:
        list_champs.append(i['Team.1'])

Aucun commentaire:

Enregistrer un commentaire