Skip to content
Advertisement

Python Pandas combinations to build the best team

I can’t simplify my data so I put them entirely. I would like to build the best possible team of 11 players according to the “niveau” column. Each “id” has a “niveau” note for the “statut” column. I think it would be necessary to test all the possible combinations of “niveau” without there being any “id” duplicates in order to obtain the best average level of the 11 players, but I don’t know how to proceed. Do you have an idea please? Thank you

JavaScript

if I do groupby(“statut”) keeping the max of the “niveau” column I have “id” duplicates, an “id” can be in several “titulaire_01” and “titulaire_02” etc.. the result should be 11 rows with no duplicates

Advertisement

Answer

It looks like an optimization problem, you can pivot your data to a rectangular format, then use scipy.optimize.linear_sum_assignment:

JavaScript

output:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement