James McCool
Enhance small_field_preset and large_field_preset functions to accept an additional parameter for excluded columns, improving filtering capabilities and lineup accuracy. Update app.py to reflect these changes in preset selections.
1b1db4f
import pandas as pd | |
def small_field_preset(portfolio: pd.DataFrame, lineup_target: int, exclude_cols: list): | |
for slack_var in range(1, 20): | |
concat_portfolio = pd.DataFrame(columns=portfolio.columns) | |
for team in portfolio['Stack'].unique(): | |
rows_to_drop = [] | |
working_portfolio = portfolio[portfolio['Stack'] == team].sort_values(by='Own', ascending = False).reset_index(drop=True) | |
working_portfolio = working_portfolio[working_portfolio['Finish_percentile'] <= .10] | |
working_portfolio = working_portfolio.reset_index(drop=True) | |
curr_own_type_max = working_portfolio.loc[0, 'Weighted Own'] + (slack_var / 20 * working_portfolio.loc[0, 'Weighted Own']) | |
for i in range(1, len(working_portfolio)): | |
if working_portfolio.loc[i, 'Weighted Own'] > curr_own_type_max: | |
rows_to_drop.append(i) | |
else: | |
curr_own_type_max = working_portfolio.loc[i, 'Weighted Own'] + (slack_var / 20 * working_portfolio.loc[i, 'Weighted Own']) | |
working_portfolio = working_portfolio.drop(rows_to_drop).reset_index(drop=True) | |
concat_portfolio = pd.concat([concat_portfolio, working_portfolio]) | |
if len(concat_portfolio) >= lineup_target: | |
return concat_portfolio.sort_values(by='Own', ascending=False).head(lineup_target) | |
return concat_portfolio.sort_values(by='Own', ascending=False) | |