vendredi 9 octobre 2020

Generate groups of people

I have a dataframe which represents people, and their two wishes to belong to a working group (there are 5 working groups, and they must be separated. For that, they state 2 wishes). We therefore have a first column of names of people, a second column (which represents a first wish to belong to a group) where these people had to enter a group number (from 1 to 5), and a third column (which represents a second wish to belong to a group) where people had to enter a group number (from 1 to 5).

Here is a reproducible example:

import pandas as pd
import numpy as np
from numpy import random

data = pd.DataFrame({"prenom" : ["personne1", "personne2", "personne3", "personne4", "personne5", "personne6", "personne7", "personne8", "personne9", "personne10", "personne11", "personne12", "personne13", "personne14", "personne15", "personne16", "personne17", "personne18", "personne19", "personne20"], "choice1" :  np.random.randint(low=1, high=5, size=(20,)), "choice2" : np.random.randint(low=1, high=5, size=(20,))})

I want to create a program that randomly distribute these people in these 5 working groups (5 groups of 4 people) taking into account their choices. In priority, we base ourselves on their first wish; otherwise, it is based on their second wish. The goal is for the 5 groups to have 4 people.

Is it possible to do this on Python?




Aucun commentaire:

Enregistrer un commentaire