Skip to content

Instantly share code, notes, and snippets.

@kraftaa
Forked from khanhnamle1994/get_best_squad.py
Created May 24, 2018 02:31
Show Gist options
  • Select an option

  • Save kraftaa/62271be69243b4182ae71de9fb657e8d to your computer and use it in GitHub Desktop.

Select an option

Save kraftaa/62271be69243b4182ae71de9fb657e8d to your computer and use it in GitHub Desktop.
Get Best Squad
def get_best_squad_n(formation, nationality, measurement = 'Overall'):
FIFA18_copy = FIFA18.copy()
FIFA18_copy = FIFA18_copy[FIFA18_copy['Nationality'] == nationality]
store = []
for i in formation:
store.append([
FIFA18_copy.loc[[FIFA18_copy[FIFA18_copy['Position'].str.contains(i)][measurement].idxmax()]]['Position'].to_string(index = False),
FIFA18_copy.loc[[FIFA18_copy[FIFA18_copy['Position'].str.contains(i)][measurement].idxmax()]]['Name'].to_string(index = False),
FIFA18_copy[FIFA18_copy['Position'].str.contains(i)][measurement].max(),
FIFA18_copy.loc[[FIFA18_copy[FIFA18_copy['Position'].str.contains(i)][measurement].idxmax()]]['Age'].to_string(index = False),
FIFA18_copy.loc[[FIFA18_copy[FIFA18_copy['Position'].str.contains(i)][measurement].idxmax()]]['Club'].to_string(index = False),
FIFA18_copy.loc[[FIFA18_copy[FIFA18_copy['Position'].str.contains(i)][measurement].idxmax()]]['Value'].to_string(index = False),
FIFA18_copy.loc[[FIFA18_copy[FIFA18_copy['Position'].str.contains(i)][measurement].idxmax()]]['Wage'].to_string(index = False)
])
FIFA18_copy.drop(FIFA18_copy[FIFA18_copy['Position'].str.contains(i)][measurement].idxmax(),
inplace = True)
return np.mean([x[2] for x in store]).round(2), pd.DataFrame(np.array(store).reshape(11,7),
columns = ['Position', 'Player', measurement, 'Age', 'Club', 'Value', 'Wage']).to_string(index = False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment