pydfs-lineup-optimizer
pydfs-lineup-optimizer copied to clipboard
How can i load my player data into optimizer through pandas DataFrame
Is there a way to load player data through a Pandas Dataframe instead of loading a CSV file. I have tried the Optimize. load_player() method but it doesnt want to accept a df. ANy help with this would be much appreciated. Thanks.
I load a temp file kind of with df I do
PATH = "/home/joe/NBA/2Slate/Playfile/"
tempFile = os.path.join(PATH, 'filtered_player_pool.csv')
temp_df.to_csv(tempFile, index=False)
optimizer = get_optimizer(Site.FANDUEL, Sport.BASKETBALL)
optimizer.load_players_from_csv(tempFile)
Not sure if you can put your dataframe to csv
The whole reason behind this is I am running 1000 Monte Carlo simulations on my projections, and what I want to do is run the optimizer for each simulation. Then aggregate all those lineups to see what percentage each player ends up in optimal lineups. I have the simulations in a Groupby in Pandas, and my thinking was to loop through each group and pass that to the Optimizer. If anyone has any ideas on how to accomplish that it would be very helpful.
I am unaware of how to load a DF vs a CSV. I am interested, though, is your MC sim returning player outcomes or DFS contest outcomes (player stats vs lineup stats)?
did you find an outcome @doublec1985
yes i figured out a way to run monte carlo simulations on my projections and then run those each through the optimizer to get percentages players were in optimal lineup. Below is approach i took.
First Monte Carlo Simulations new_df=pd.DataFrame()
group = 1 for i in range(1001): df['FPPG']= rn.gauss(df['Projection'], df['STD']) df['grp']= group new_df = new_df.append(df) group+=1
Then created a function to run the optimizer: def opt_simulation(file): optimizer=get_optimizer(Site.FANDUEL, Sport.BASKETBALL) optimizer.load_players_from_csv(file) optimizer.set_fantasy_points_strategy(RandomFantasyPointsStrategy()) optimizer.set_max_repeating_players(5) lineups=optimizer.optimize(n=1) return lineups
Finally run each simulation through optimizer and put into DF: simlines = pd.DataFrame() PATH = 'Path you want to drop files at' for i in range(1,1001): files = new_df[new_df['grp']== i] files.to_csv(r'Path files are saved at', index=False) file = os.path.join(PATH, 'Optimal.csv') lineups = opt_simulation(file) for b in lineups: sim = list(b.lineup) sim = pd.DataFrame(sim) simlines = simlines.append(sim) os.remove(file)
That was my approach let me know if you have any questions
What is doing the simulations
On Fri, Jul 8, 2022, 7:12 PM doublec1985 @.***> wrote:
yes i figured out a way to run monte carlo simulations on my projections and then run those each through the optimizer to get percentages players were in optimal lineup. Below is approach i took.
First Monte Carlo Simulations new_df=pd.DataFrame()
group = 1 for i in range(1001): df['FPPG']= rn.gauss(df['Projection'], df['STD']) df['grp']= group new_df = new_df.append(df) group+=1
Then created a function to run the optimizer: def opt_simulation(file): optimizer=get_optimizer(Site.FANDUEL, Sport.BASKETBALL) optimizer.load_players_from_csv(file) optimizer.set_fantasy_points_strategy(RandomFantasyPointsStrategy()) optimizer.set_max_repeating_players(5) lineups=optimizer.optimize(n=1) return lineups
Finally run each simulation through optimizer and put into DF: simlines = pd.DataFrame() PATH = 'Path you want to drop files at' for i in range(1,1001): files = new_df[new_df['grp']== i] files.to_csv(r'Path files are saved at', index=False) file = os.path.join(PATH, 'Optimal.csv') lineups = opt_simulation(file) for b in lineups: sim = list(b.lineup) sim = pd.DataFrame(sim) simlines = simlines.append(sim) os.remove(file)
That was my approach let me know if you have any questions
— Reply to this email directly, view it on GitHub https://github.com/DimaKudosh/pydfs-lineup-optimizer/issues/354#issuecomment-1179422087, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANBWO7XVKQ76LDUGXFLB4OLVTCYVZANCNFSM5SN4L7UA . You are receiving this because you commented.Message ID: @.***>