I am trying to develop a code to select the best 11 possible players out of 200 players. I have developed a spreadsheet with the players prices and points so far and imported it to a DF using Pandas as below,
import pandas as pd
import numpy as np
df=pd.read_excel('FPL.xlsx')
print(df)
Player Price Points Position Select
0 Henderson 4.9 79 GK 1
1 Foster 4.8 79 GK 1
2 Ryan 4.8 78 GK 1
3 Schmeichel 5.4 78 GK 1
4 Ramsdale 4.7 76 GK 1
5 Guaita 5.1 76 GK 1
....
200
df['select price']=df['Price']*df['Select']
df['select points']=df['Points']*df['Select']
sumpoints=df['select points'].sum()
sumplayers=df['Select'].sum()
sumprice=df['select price'].sum()
My idea was to create a select column and multiply it by both the price column and the points columns, then the optimization problem will be as follows:
- Objective function: maximize the sum of
Select*points
- Constraints:
- The team is composed of only 11 players
- The budget to buy the players is 85
- Number of goalkeepers (GK) must be 1
- Number of DF must be 3
This will be done by changing the variables in the select column to be 0 or 1 (i.e. 1 if the player of the corresponding row gets selected for taking part of the team, and 0 otherwise).
This is very straight forward if using the excel solver but I want to learn how to do it in Python.