In [139]:
import pandas as pd
from itertools import combinations
from pprint import pprint
import operator

divers = pd.read_csv("teams.csv", index_col='name')
divers


Out[139]:
tierra dimar datatre sella dev ds design desc
name
giorgio 0 0 0 1 NaN 1 NaN (data science)
Tobias 1 0 1 0 NaN 1 NaN (geographer)
Elena 0 1 1 0 1 NaN NaN (inf. engineering)
Simone 0 1 0 1 1 NaN NaN (dev)
Isabella 0 0 0 1 NaN 1 NaN (data science/stats)
Massimo 0 0 1 0 NaN NaN 1 /design/social.network.analysis
Andrea Marchini 0 0 1 1 NaN 1 NaN (Data Science)
Lorenzo 0 0 1 1 NaN 1 NaN physics background and expertise in sport betting
Gianni 1 0 1 0 1 NaN NaN Frontend/Backend Development/DB/JS/Visualization
Roberto 0 0 1 1 NaN 1 NaN (data science)
andrea corradi 1 1 1 0 NaN NaN 1 (design and visualization)
Hai 1 0 0 0 1 NaN NaN telecommunication, optimization
Alberto 1 0 1 0 NaN NaN 1 (UX Designer)
Adam 1 1 1 1 NaN 1 NaN (data science/machine learning)
Chiara 0 1 1 0 NaN 1 NaN (NLP, pattern analysis)
Gianluca 0 0 0 1 1 NaN NaN NaN
Lionel 1 0 1 0 NaN NaN 1 design/business
Enrico 0 0 1 1 1 NaN NaN (dev/data science)
Alfredo 0 1 0 1 1 NaN NaN dev

Adam, Andrea, Chiara and Elena have pretty much decided on Dimar. If you don't want to delete them, comment out this line:


In [140]:
allDivers = divers.copy()
divers = divers.drop(divers.index[[2, 10, 13, 14]])

In [144]:
tierra = divers[divers['tierra'] == 1]
dimar = allDivers[allDivers['dimar'] == 1]
datatre = divers[divers['datatre'] == 1]
sella = divers[divers['sella'] == 1]

In [145]:
tierra


Out[145]:
tierra dimar datatre sella dev ds design desc
name
Tobias 1 0 1 0 NaN 1 NaN (geographer)
Gianni 1 0 1 0 1 NaN NaN Frontend/Backend Development/DB/JS/Visualization
Hai 1 0 0 0 1 NaN NaN telecommunication, optimization
Alberto 1 0 1 0 NaN NaN 1 (UX Designer)
Lionel 1 0 1 0 NaN NaN 1 design/business

In [146]:
dimar


Out[146]:
tierra dimar datatre sella dev ds design desc
name
Elena 0 1 1 0 1 NaN NaN (inf. engineering)
Simone 0 1 0 1 1 NaN NaN (dev)
andrea corradi 1 1 1 0 NaN NaN 1 (design and visualization)
Adam 1 1 1 1 NaN 1 NaN (data science/machine learning)
Chiara 0 1 1 0 NaN 1 NaN (NLP, pattern analysis)
Alfredo 0 1 0 1 1 NaN NaN dev

In [147]:
datatre


Out[147]:
tierra dimar datatre sella dev ds design desc
name
Tobias 1 0 1 0 NaN 1 NaN (geographer)
Massimo 0 0 1 0 NaN NaN 1 /design/social.network.analysis
Andrea Marchini 0 0 1 1 NaN 1 NaN (Data Science)
Lorenzo 0 0 1 1 NaN 1 NaN physics background and expertise in sport betting
Gianni 1 0 1 0 1 NaN NaN Frontend/Backend Development/DB/JS/Visualization
Roberto 0 0 1 1 NaN 1 NaN (data science)
Alberto 1 0 1 0 NaN NaN 1 (UX Designer)
Lionel 1 0 1 0 NaN NaN 1 design/business
Enrico 0 0 1 1 1 NaN NaN (dev/data science)

In [148]:
sella


Out[148]:
tierra dimar datatre sella dev ds design desc
name
giorgio 0 0 0 1 NaN 1 NaN (data science)
Simone 0 1 0 1 1 NaN NaN (dev)
Isabella 0 0 0 1 NaN 1 NaN (data science/stats)
Andrea Marchini 0 0 1 1 NaN 1 NaN (Data Science)
Lorenzo 0 0 1 1 NaN 1 NaN physics background and expertise in sport betting
Roberto 0 0 1 1 NaN 1 NaN (data science)
Gianluca 0 0 0 1 1 NaN NaN NaN
Enrico 0 0 1 1 1 NaN NaN (dev/data science)
Alfredo 0 1 0 1 1 NaN NaN dev

In [156]:
def computeScores(teamDF, howManyToPrint=10):

    ranking = []
    combs = combinations(teamDF.T, 5)

    #define scores given to a second diver of the kind
    skillscores = {'dev': 0.5, 'ds': 0.5, 'design': 0.2}

    for comb in combs:
        skillset = {'dev': 0, 'ds': 0, 'design': 0}
        score = 0
        for name in comb:
            for skill in ('dev', 'ds', 'design'):
                if allDivers.ix[name][skill] == 1:
                    
                    #add skill to the team's skillset
                    skillset[skill] += 1

                    #first skill of its kind is better than the next
                    if skillset[skill] == 1:
                        score += 1
                    else:
                        score += skillscores[skill]
        
        #penalty for not having one of the skills
        for skill in skillset:
            if skillset[skill] == 0:
                score -= 1
        
        #penalty for the difference between the number of the most well represented skill and the next one being greater than 1(e.g. if there are 4 devs and 1 data scientist)
        sortedSkillset = sorted(skillset.items(), key=operator.itemgetter(1))
        if (sortedSkillset[2][1] - sortedSkillset[1][1]) > 1:
            score -= 1


        ranking.append({'score': score, 'skillset': skillset, 'names': comb})

    import pprint

    for team in (sorted(ranking, key=lambda x: -1*x['score']))[:howManyToPrint]:
        pprint.pprint(team)

In [157]:
computeScores(tierra)


{'names': ('Tobias', 'Gianni', 'Hai', 'Alberto', 'Lionel'),
 'score': 3.7,
 'skillset': {'design': 2, 'dev': 2, 'ds': 1}}

In [158]:
computeScores(dimar)


{'names': ('Elena', 'Simone', 'andrea corradi', 'Adam', 'Chiara'),
 'score': 4.0,
 'skillset': {'design': 1, 'dev': 2, 'ds': 2}}
{'names': ('Elena', 'andrea corradi', 'Adam', 'Chiara', 'Alfredo'),
 'score': 4.0,
 'skillset': {'design': 1, 'dev': 2, 'ds': 2}}
{'names': ('Simone', 'andrea corradi', 'Adam', 'Chiara', 'Alfredo'),
 'score': 4.0,
 'skillset': {'design': 1, 'dev': 2, 'ds': 2}}
{'names': ('Elena', 'Simone', 'andrea corradi', 'Adam', 'Alfredo'),
 'score': 3.0,
 'skillset': {'design': 1, 'dev': 3, 'ds': 1}}
{'names': ('Elena', 'Simone', 'andrea corradi', 'Chiara', 'Alfredo'),
 'score': 3.0,
 'skillset': {'design': 1, 'dev': 3, 'ds': 1}}
{'names': ('Elena', 'Simone', 'Adam', 'Chiara', 'Alfredo'),
 'score': 2.5,
 'skillset': {'design': 0, 'dev': 3, 'ds': 2}}

In [159]:
computeScores(datatre, 20)


{'names': ('Tobias', 'Massimo', 'Andrea Marchini', 'Gianni', 'Enrico'),
 'score': 4.0,
 'skillset': {'design': 1, 'dev': 2, 'ds': 2}}
{'names': ('Tobias', 'Massimo', 'Lorenzo', 'Gianni', 'Enrico'),
 'score': 4.0,
 'skillset': {'design': 1, 'dev': 2, 'ds': 2}}
{'names': ('Tobias', 'Massimo', 'Gianni', 'Roberto', 'Enrico'),
 'score': 4.0,
 'skillset': {'design': 1, 'dev': 2, 'ds': 2}}
{'names': ('Tobias', 'Andrea Marchini', 'Gianni', 'Alberto', 'Enrico'),
 'score': 4.0,
 'skillset': {'design': 1, 'dev': 2, 'ds': 2}}
{'names': ('Tobias', 'Andrea Marchini', 'Gianni', 'Lionel', 'Enrico'),
 'score': 4.0,
 'skillset': {'design': 1, 'dev': 2, 'ds': 2}}
{'names': ('Tobias', 'Lorenzo', 'Gianni', 'Alberto', 'Enrico'),
 'score': 4.0,
 'skillset': {'design': 1, 'dev': 2, 'ds': 2}}
{'names': ('Tobias', 'Lorenzo', 'Gianni', 'Lionel', 'Enrico'),
 'score': 4.0,
 'skillset': {'design': 1, 'dev': 2, 'ds': 2}}
{'names': ('Tobias', 'Gianni', 'Roberto', 'Alberto', 'Enrico'),
 'score': 4.0,
 'skillset': {'design': 1, 'dev': 2, 'ds': 2}}
{'names': ('Tobias', 'Gianni', 'Roberto', 'Lionel', 'Enrico'),
 'score': 4.0,
 'skillset': {'design': 1, 'dev': 2, 'ds': 2}}
{'names': ('Massimo', 'Andrea Marchini', 'Lorenzo', 'Gianni', 'Enrico'),
 'score': 4.0,
 'skillset': {'design': 1, 'dev': 2, 'ds': 2}}
{'names': ('Massimo', 'Andrea Marchini', 'Gianni', 'Roberto', 'Enrico'),
 'score': 4.0,
 'skillset': {'design': 1, 'dev': 2, 'ds': 2}}
{'names': ('Massimo', 'Lorenzo', 'Gianni', 'Roberto', 'Enrico'),
 'score': 4.0,
 'skillset': {'design': 1, 'dev': 2, 'ds': 2}}
{'names': ('Andrea Marchini', 'Lorenzo', 'Gianni', 'Alberto', 'Enrico'),
 'score': 4.0,
 'skillset': {'design': 1, 'dev': 2, 'ds': 2}}
{'names': ('Andrea Marchini', 'Lorenzo', 'Gianni', 'Lionel', 'Enrico'),
 'score': 4.0,
 'skillset': {'design': 1, 'dev': 2, 'ds': 2}}
{'names': ('Andrea Marchini', 'Gianni', 'Roberto', 'Alberto', 'Enrico'),
 'score': 4.0,
 'skillset': {'design': 1, 'dev': 2, 'ds': 2}}
{'names': ('Andrea Marchini', 'Gianni', 'Roberto', 'Lionel', 'Enrico'),
 'score': 4.0,
 'skillset': {'design': 1, 'dev': 2, 'ds': 2}}
{'names': ('Lorenzo', 'Gianni', 'Roberto', 'Alberto', 'Enrico'),
 'score': 4.0,
 'skillset': {'design': 1, 'dev': 2, 'ds': 2}}
{'names': ('Lorenzo', 'Gianni', 'Roberto', 'Lionel', 'Enrico'),
 'score': 4.0,
 'skillset': {'design': 1, 'dev': 2, 'ds': 2}}
{'names': ('Tobias', 'Massimo', 'Andrea Marchini', 'Gianni', 'Alberto'),
 'score': 3.7,
 'skillset': {'design': 2, 'dev': 1, 'ds': 2}}
{'names': ('Tobias', 'Massimo', 'Andrea Marchini', 'Gianni', 'Lionel'),
 'score': 3.7,
 'skillset': {'design': 2, 'dev': 1, 'ds': 2}}

In [160]:
computeScores(sella, 20)


{'names': ('giorgio', 'Simone', 'Isabella', 'Andrea Marchini', 'Gianluca'),
 'score': 2.5,
 'skillset': {'design': 0, 'dev': 2, 'ds': 3}}
{'names': ('giorgio', 'Simone', 'Isabella', 'Andrea Marchini', 'Enrico'),
 'score': 2.5,
 'skillset': {'design': 0, 'dev': 2, 'ds': 3}}
{'names': ('giorgio', 'Simone', 'Isabella', 'Andrea Marchini', 'Alfredo'),
 'score': 2.5,
 'skillset': {'design': 0, 'dev': 2, 'ds': 3}}
{'names': ('giorgio', 'Simone', 'Isabella', 'Lorenzo', 'Gianluca'),
 'score': 2.5,
 'skillset': {'design': 0, 'dev': 2, 'ds': 3}}
{'names': ('giorgio', 'Simone', 'Isabella', 'Lorenzo', 'Enrico'),
 'score': 2.5,
 'skillset': {'design': 0, 'dev': 2, 'ds': 3}}
{'names': ('giorgio', 'Simone', 'Isabella', 'Lorenzo', 'Alfredo'),
 'score': 2.5,
 'skillset': {'design': 0, 'dev': 2, 'ds': 3}}
{'names': ('giorgio', 'Simone', 'Isabella', 'Roberto', 'Gianluca'),
 'score': 2.5,
 'skillset': {'design': 0, 'dev': 2, 'ds': 3}}
{'names': ('giorgio', 'Simone', 'Isabella', 'Roberto', 'Enrico'),
 'score': 2.5,
 'skillset': {'design': 0, 'dev': 2, 'ds': 3}}
{'names': ('giorgio', 'Simone', 'Isabella', 'Roberto', 'Alfredo'),
 'score': 2.5,
 'skillset': {'design': 0, 'dev': 2, 'ds': 3}}
{'names': ('giorgio', 'Simone', 'Isabella', 'Gianluca', 'Enrico'),
 'score': 2.5,
 'skillset': {'design': 0, 'dev': 3, 'ds': 2}}
{'names': ('giorgio', 'Simone', 'Isabella', 'Gianluca', 'Alfredo'),
 'score': 2.5,
 'skillset': {'design': 0, 'dev': 3, 'ds': 2}}
{'names': ('giorgio', 'Simone', 'Isabella', 'Enrico', 'Alfredo'),
 'score': 2.5,
 'skillset': {'design': 0, 'dev': 3, 'ds': 2}}
{'names': ('giorgio', 'Simone', 'Andrea Marchini', 'Lorenzo', 'Gianluca'),
 'score': 2.5,
 'skillset': {'design': 0, 'dev': 2, 'ds': 3}}
{'names': ('giorgio', 'Simone', 'Andrea Marchini', 'Lorenzo', 'Enrico'),
 'score': 2.5,
 'skillset': {'design': 0, 'dev': 2, 'ds': 3}}
{'names': ('giorgio', 'Simone', 'Andrea Marchini', 'Lorenzo', 'Alfredo'),
 'score': 2.5,
 'skillset': {'design': 0, 'dev': 2, 'ds': 3}}
{'names': ('giorgio', 'Simone', 'Andrea Marchini', 'Roberto', 'Gianluca'),
 'score': 2.5,
 'skillset': {'design': 0, 'dev': 2, 'ds': 3}}
{'names': ('giorgio', 'Simone', 'Andrea Marchini', 'Roberto', 'Enrico'),
 'score': 2.5,
 'skillset': {'design': 0, 'dev': 2, 'ds': 3}}
{'names': ('giorgio', 'Simone', 'Andrea Marchini', 'Roberto', 'Alfredo'),
 'score': 2.5,
 'skillset': {'design': 0, 'dev': 2, 'ds': 3}}
{'names': ('giorgio', 'Simone', 'Andrea Marchini', 'Gianluca', 'Enrico'),
 'score': 2.5,
 'skillset': {'design': 0, 'dev': 3, 'ds': 2}}
{'names': ('giorgio', 'Simone', 'Andrea Marchini', 'Gianluca', 'Alfredo'),
 'score': 2.5,
 'skillset': {'design': 0, 'dev': 3, 'ds': 2}}

In [ ]: