<jupyter_start><jupyter_text>![world-cup-18](images/fifa-world-cup-2018.jpg)<jupyter_code># Import libraries
import pandas as pd
import numpy as np

import seaborn as sns
import matplotlib.pyplot as plt
%matplotlib inline

from plotly.offline import iplot, init_notebook_mode
from geopy.geocoders import Nominatim
import plotly.plotly as py<jupyter_output><empty_output><jupyter_text>1 - Data Preparation 1.1 Load Data<jupyter_code>FIFA18 = pd.read_csv('CompleteDataset.csv', low_memory=False)
FIFA18.columns<jupyter_output><empty_output><jupyter_text>Let's select the most interesting columns from loaded dataset:<jupyter_code>interesting_columns = [
    'Name', 
    'Age',  
    'Nationality', 
    'Overall', 
    'Potential', 
    'Club', 
    'Value', 
    'Wage', 
    'Preferred Positions'
]
FIFA18 = pd.DataFrame(FIFA18, columns=interesting_columns)<jupyter_output><empty_output><jupyter_text>1.2 Summarize Data<jupyter_code>FIFA18.head()
FIFA18.info()<jupyter_output><class 'pandas.core.frame.DataFrame'>
RangeIndex: 17981 entries, 0 to 17980
Data columns (total 9 columns):
Name                   17981 non-null object
Age                    17981 non-null int64
Nationality            17981 non-null object
Overall                17981 non-null int64
Potential              17981 non-null int64
Club                   17733 non-null object
Value                  17981 non-null object
Wage                   17981 non-null object
Preferred Positions    17981 non-null object
dtypes: int64(3), object(6)
memory usage: 1.2+ MB<jupyter_text>1.3 Preprocess DataRight away I can see that values in columns: 'Value' and 'Wage' aren't numeric but objects. Thus I'll preprocess the data to make it usable. I will use short supporting function to convert values in those two columns into numbers. I will end up with two new columns 'ValueNum' and 'WageNum' that will contain numeric values.<jupyter_code># Supporting function for converting string values into numbers
def str2number(amount):
    if amount[-1] == 'M':
        return float(amount[1:-1])*1000000
    elif amount[-1] == 'K':
        return float(amount[1:-1])*1000
    else:
        return float(amount[1:])
    
FIFA18['ValueNum'] = FIFA18['Value'].apply(lambda x: str2number(x))
FIFA18['WageNum'] = FIFA18['Wage'].apply(lambda x: str2number(x))<jupyter_output><empty_output><jupyter_text>To make things simpler, I select the first position from list as preferred and save it in 'Position' column.<jupyter_code>FIFA18['Position'] = FIFA18['Preferred Positions'].str.split().str[0]<jupyter_output><empty_output><jupyter_text>2 - Data Visualization 2.1 Age<jupyter_code>plt.figure(figsize=(16,8))
sns.set_style("whitegrid")
plt.title('Grouping players by Age', fontsize=30, fontweight='bold', y=1.05,)
plt.xlabel('Number of players', fontsize=25)
plt.ylabel('Players Age', fontsize=25)
sns.countplot(x="Age", data=FIFA18, palette="hls");
plt.show()<jupyter_output><empty_output><jupyter_text>2.2 Overall<jupyter_code>plt.figure(figsize=(16,8))
sns.set_style("whitegrid")
plt.title('Grouping players by Overall', fontsize=30, fontweight='bold', y=1.05,)
plt.xlabel('Number of players', fontsize=25)
plt.ylabel('Players Age', fontsize=25)
sns.countplot(x="Overall", data=FIFA18, palette="hls");
plt.show()<jupyter_output><empty_output><jupyter_text>2.3 Preferred Position<jupyter_code>plt.figure(figsize=(16,8))
sns.set_style("whitegrid")
plt.title('Grouping players by Preferred Position', fontsize=30, fontweight='bold', y=1.05,)
plt.xlabel('Number of players', fontsize=25)
plt.ylabel('Players Age', fontsize=25)
sns.countplot(x="Position", data=FIFA18, palette="hls");
plt.show()<jupyter_output><empty_output><jupyter_text>2.4 Nationality<jupyter_code># Grouping the data by countries
valcon = FIFA18.groupby("Nationality").size().reset_index(name="Count")

# Plotting the choropleth map
init_notebook_mode()
plotmap = [ dict(
        type = 'choropleth',
        locations = valcon["Nationality"],
        locationmode = 'country names',
        z = valcon["Count"],
        text = valcon["Nationality"],
        autocolorscale = True,
        reversescale = False,
        marker = dict(
            line = dict (
                color = 'rgb(180,180,180)',
                width = 0.5
            ) ),
        colorbar = dict(
            title = "Amount of Players"),
      ) ]

layout = dict(
    title = "Nationalities of FIFA 18 Players",
    geo = dict(
        showframe = False,
        showcoastlines = False,
        projection = dict(
            type = 'Mercator'
        )
    )
)

fig = dict( data=plotmap, layout=layout )
iplot(fig)<jupyter_output>IOPub data rate exceeded.
The notebook server will temporarily stop sending output
to the client in order to avoid crashing it.
To change this limit, set the config variable
`--NotebookApp.iopub_data_rate_limit`.<jupyter_text>In case the plot.ly image doesn't show:![nationalities](images/Nationalities.png)<jupyter_code>FIFA18["Nationality"].value_counts().head(25)<jupyter_output><empty_output><jupyter_text>I can see that the players are very centralized in Europe. To be precise, England, Germany, Spain, and France. 2.5 ValueLet's see the 20 players with highest value:<jupyter_code>sorted_players = FIFA18.sort_values(["ValueNum"], ascending=False).head(20)
players = sorted_players[["Name" ,"Age" ,"Nationality" ,"Club" ,"Position" ,"Value"]].values
from IPython.display import HTML, display

table_content = ''
for row in players:
    HTML_row = '<tr>'
    HTML_row += '<td>' + str(row[0]) + '</td>'
    HTML_row += '<td>' + str(row[1]) + '</td>'
    HTML_row += '<td>' + str(row[2]) + '</td>'
    HTML_row += '<td>' + str(row[3]) + '</td>'
    HTML_row += '<td>' + str(row[4]) + '</td>'
    HTML_row += '<td>' + str(row[5]) + '</td>'
    
    table_content += HTML_row + '</tr>'

display(HTML(
    '<table><tr><th>Name</th><th>Age</th><th>Nationality</th><th>Club</th><th>Position</th><th>Value</th></tr>{}</table>'.format(table_content))
)<jupyter_output><empty_output><jupyter_text>Let's make a scatter chart of the players' Value with respect to their Age and Overall:<jupyter_code>plt.figure(figsize=(16,8))
sns.set_style("whitegrid")
plt.title('Players Value according to their Age and Overall', fontsize=30, fontweight='bold', y=1.05,)
plt.xlabel('Age', fontsize=25)
plt.ylabel('Overall', fontsize=25)

age = FIFA18["Age"].values
overall = FIFA18["Overall"].values
value = FIFA18["ValueNum"].values

plt.scatter(age, overall, s = value/100000, edgecolors='black')
plt.show()<jupyter_output><empty_output><jupyter_text>2.6 WageLet's see the 20 players with highest wage:<jupyter_code>sorted_players = FIFA18.sort_values(["WageNum"], ascending=False).head(20)
players = sorted_players[["Name" ,"Age" ,"Nationality" ,"Club" ,"Position" ,"Wage"]].values
from IPython.display import HTML, display

table_content = ''
for row in players:
    HTML_row = '<tr>'
    HTML_row += '<td>' + str(row[0]) + '</td>'
    HTML_row += '<td>' + str(row[1]) + '</td>'
    HTML_row += '<td>' + str(row[2]) + '</td>'
    HTML_row += '<td>' + str(row[3]) + '</td>'
    HTML_row += '<td>' + str(row[4]) + '</td>'
    HTML_row += '<td>' + str(row[5]) + '</td>'
    
    table_content += HTML_row + '</tr>'

display(HTML(
    '<table><tr><th>Name</th><th>Age</th><th>Nationality</th><th>Club</th><th>Position</th><th>Wage</th></tr>{}</table>'.format(table_content))
)<jupyter_output><empty_output><jupyter_text>Let's make a scatter chart of the players' Wage with respect to their Age and Overall:<jupyter_code>plt.figure(figsize=(16,8))
sns.set_style("whitegrid")
plt.title('Players Wage according to their Age and Overall', fontsize=30, fontweight='bold', y=1.05,)
plt.xlabel('Age', fontsize=25)
plt.ylabel('Overall', fontsize=25)

age = FIFA18["Age"].values
overall = FIFA18["Overall"].values
value = FIFA18["WageNum"].values

plt.scatter(age, overall, s = value/500, edgecolors='black', color="red")
plt.show()<jupyter_output><empty_output><jupyter_text>3 - Best Squad AnalysisFor simplicity of this analysis, I only pull in data I am interested in:<jupyter_code>FIFA18 = FIFA18[['Name', 'Age', 'Nationality', 'Overall', 'Potential', 'Club', 'Position', 'Value', 'Wage']]
FIFA18.head(10)<jupyter_output><empty_output><jupyter_text>3.1 Squad of Highest Overall PlayersWhat's the best squad according to FIFA 18 purely based on overall rating?<jupyter_code>def get_best_squad(formation):
    FIFA18_copy = FIFA18.copy()
    store = []
    
    # iterate through all positions in the input formation and get players with highest overall respective to the position
    for i in formation:
        store.append([
            i,
            FIFA18_copy.loc[[FIFA18_copy[FIFA18_copy['Position'] == i]['Overall'].idxmax()]]['Name'].to_string(index = False),
            FIFA18_copy[FIFA18_copy['Position'] == i]['Overall'].max(),
            FIFA18_copy.loc[[FIFA18_copy[FIFA18_copy['Position'] == i]['Overall'].idxmax()]]['Age'].to_string(index = False),
            FIFA18_copy.loc[[FIFA18_copy[FIFA18_copy['Position'] == i]['Overall'].idxmax()]]['Club'].to_string(index = False),
            FIFA18_copy.loc[[FIFA18_copy[FIFA18_copy['Position'] == i]['Overall'].idxmax()]]['Value'].to_string(index = False),
            FIFA18_copy.loc[[FIFA18_copy[FIFA18_copy['Position'] == i]['Overall'].idxmax()]]['Wage'].to_string(index = False)
        ])
                      
        FIFA18_copy.drop(FIFA18_copy[FIFA18_copy['Position'] == i]['Overall'].idxmax(), 
                         inplace = True)
    
    # return store with only necessary columns
    return pd.DataFrame(np.array(store).reshape(11,7), 
                        columns = ['Position', 'Player', 'Overall', 'Age', 'Club', 'Value', 'Wage']).to_string(index = False)
# 4-3-3
squad_433 = ['GK', 'RB', 'CB', 'CB', 'LB', 'CDM', 'CM', 'CAM', 'RW', 'ST', 'LW']
print ('4-3-3')
print (get_best_squad(squad_433))
# 4-4-2
squad_442 = ['GK', 'RB', 'CB', 'CB', 'LB', 'RM', 'CM', 'CM', 'LM', 'ST', 'ST']
print ('4-4-2')
print (get_best_squad(squad_442))
# 4-2-3-1
squad_4231 = ['GK', 'RB', 'CB', 'CB', 'LB', 'CDM', 'CDM', 'CAM', 'CAM', 'CAM', 'ST']
print ('4-2-3-1')
print (get_best_squad(squad_4231))<jupyter_output>4-2-3-1
Position             Player Overall Age              Club   Value   Wage
     GK           <NAME>      92  31  FC Bayern Munich    €61M  €230K
     RB           Carvajal      84  25    Real Madrid CF    €32M  €195K
     CB       <NAME>      90  31    Real Madrid CF    €52M  €310K
     CB       <NAME>      89  32          Juventus    €38M  €225K
     LB            Marcelo      87  29    Real Madrid CF    €38M  €250K
    CDM           <NAME>      90  27    Real Madrid CF    €79M  €340K
    CDM          <NAME>      89  31    Real Madrid CF    €57M  €340K
    CAM           Coutinho      86  25         Liverpool    €56M  €205K
    CAM      <NAME>      86  29              Roma  €42.5M  €130K
    CAM      <NAME>      86  30           Chelsea    €41M  €210K
     ST  <NAME>      94  32    Real Madrid CF  €95.5M  €565K<jupyter_text>Alright, now let's move onto studying different squad's impact on Nationality teams. First let's modifiy above get_summary and get_best_squad functions for Nationality:<jupyter_code>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)
def get_summary_n(squad_list, squad_name, nationality_list):
    summary = []

    for i in nationality_list:
        count = 0
        for j in squad_list:
            
            # for overall rating
            O_temp_rating, _  = get_best_squad_n(formation = j, nationality = i, measurement = 'Overall')
            
            # for potential rating & corresponding value
            P_temp_rating, _ = get_best_squad_n(formation = j, nationality = i, measurement = 'Potential')
            
            summary.append([i, squad_name[count], O_temp_rating.round(2), P_temp_rating.round(2)])    
            count += 1
    
    return summary<jupyter_output><empty_output><jupyter_text>Also let's make our squad choices more strict:<jupyter_code>squad_343_strict = ['GK', 'CB', 'CB', 'CB', 'RB|RWB', 'CM|CDM', 'CM|CDM', 'LB|LWB', 'RM|RW', 'ST|CF', 'LM|LW']
squad_442_strict = ['GK', 'RB|RWB', 'CB', 'CB', 'LB|LWB', 'RM', 'CM|CDM', 'CM|CAM', 'LM', 'ST|CF', 'ST|CF']
squad_4312_strict = ['GK', 'RB|RWB', 'CB', 'CB', 'LB|LWB', 'CM|CDM', 'CM|CAM|CDM', 'CM|CAM|CDM', 'CAM|CF', 'ST|CF', 'ST|CF']
squad_433_strict = ['GK', 'RB|RWB', 'CB', 'CB', 'LB|LWB', 'CM|CDM', 'CM|CAM|CDM', 'CM|CAM|CDM', 'RM|RW', 'ST|CF', 'LM|LW']
squad_4231_strict = ['GK', 'RB|RWB', 'CB', 'CB', 'LB|LWB', 'CM|CDM', 'CM|CDM', 'RM|RW', 'CAM', 'LM|LW', 'ST|CF']
squad_list = [squad_343_strict, squad_442_strict, squad_4312_strict, squad_433_strict, squad_4231_strict]
squad_name = ['3-4-3', '4-4-2', '4-3-1-2', '4-3-3', '4-2-3-1']<jupyter_output><empty_output><jupyter_text>3.2 FranceLet's explore different squad possibility of France and how it affects the ratings:<jupyter_code>France = pd.DataFrame(np.array(get_summary_n(squad_list, squad_name, ['France'])).reshape(-1,4), columns = ['Nationality', 'Squad', 'Overall', 'Potential'])
France.set_index('Nationality', inplace = True)
France[['Overall', 'Potential']] = France[['Overall', 'Potential']].astype(float)

print (France)<jupyter_output>Squad  Overall  Potential
Nationality                             
France         3-4-3    84.55      89.55
France         4-4-2    84.00      89.91
France       4-3-1-2    84.55      89.64
France         4-3-3    84.64      89.91
France       4-2-3-1    84.55      89.91<jupyter_text>So we can say that France has the best squard as 4-3-3 for the current squad; and 4-4-2, 4-3-3, and 4-2-3-1 for the future squad based on team ratings. Let's check out the best 11 squad line-up of France in 4-3-3 for current rating as well as 4-4-2 for potential rating:<jupyter_code>rating_433_FR_Overall, best_list_433_FR_Overall = get_best_squad_n(squad_433_strict, 'France', 'Overall')
print('-Overall-')
print('Average rating: {:.1f}'.format(rating_433_FR_Overall))
print(best_list_433_FR_Overall)
rating_442_FR_Potential, best_list_442_FR_Potential = get_best_squad_n(squad_442_strict, 'France', 'Potential')
print('-Potential-')
print('Average rating: {:.1f}'.format(rating_442_FR_Potential))
print(best_list_442_FR_Potential)<jupyter_output>-Potential-
Average rating: 89.9
Position        Player Potential Age                     Club   Value   Wage
     GK     <NAME>        89  18              Toulouse FC  €11.5M   €10K
     RB      <NAME>        86  22               Stoke City    €15M   €96K
     CB     <NAME>        92  24           Real Madrid CF  €46.5M  €175K
     CB    <NAME>        89  23  Athletic Club de Bilbao  €35.5M   €36K
     LB  <NAME>        88  21          Atlético Madrid  €13.5M   €36K
     RM       <NAME>        86  24                 OGC Nice  €20.5M   €41K
    CDM      <NAME>        92  24        Manchester United  €66.5M  €195K
    CAM    <NAME>        92  20             FC Barcelona    €40M  €150K
     LM      <NAME>        91  21                AS Monaco  €38.5M   €37K
     ST     <NAME>        94  18      Paris Saint-Germain  €41.5M   €31K
     ST    <NAME>        90  21        Manchester United    €33M  €115K<jupyter_text>![griezmann](images/griezmann.jpeg) 3.3 GermanyThe holding champion is certainly a heavy candidate for this year's 1st place:<jupyter_code>Germany = pd.DataFrame(np.array(get_summary_n(squad_list, squad_name, ['Germany'])).reshape(-1,4), columns = ['Nationality', 'Squad', 'Overall', 'Potential'])
Germany.set_index('Nationality', inplace = True)
Germany[['Overall', 'Potential']] = Germany[['Overall', 'Potential']].astype(float)

print (Germany)<jupyter_output>Squad  Overall  Potential
Nationality                             
Germany        3-4-3    86.27      88.55
Germany        4-4-2    85.09      88.36
Germany      4-3-1-2    85.36      88.00
Germany        4-3-3    86.27      88.55
Germany      4-2-3-1    86.09      88.55<jupyter_text>As you can see, Germany's current ratings peak with either 3-4-3 or 4-3-3 formation; while those 2 plus 4-2-3-1 are their best options for the future. With that, I'll show Germany's best 11 squad with 4-3-3 for current ratings and 4-2-3-1 for potential ratings.<jupyter_code>rating_433_GER_Overall, best_list_433_GER_Overall = get_best_squad_n(squad_433_strict, 'Germany', 'Overall')
print('-Overall-')
print('Average rating: {:.1f}'.format(rating_433_GER_Overall))
print(best_list_433_GER_Overall)
rating_4231_GER_Potential, best_list_4231_GER_Potential = get_best_squad_n(squad_4231_strict, 'Germany', 'Potential')
print('-Potential-')
print('Average rating: {:.1f}'.format(rating_4231_GER_Potential))
print(best_list_4231_GER_Potential)<jupyter_output>-Potential-
Average rating: 88.5
Position       Player Potential Age                 Club   Value   Wage
     GK     <NAME>        92  31     FC Bayern Munich    €61M  €230K
     RB   <NAME>        86  24              Chelsea  €24.5M  €105K
     CB      <NAME>        89  21     FC Bayern Munich  €30.5M   €78K
     CB   <NAME>        88  28     FC Bayern Munich    €48M  €215K
     LB  <NAME>        86  20  Bayer 04 Leverkusen    €11M   €36K
    CDM     <NAME>        90  27       Real Madrid CF    €79M  €340K
    CDM  <NAME>        88  22        FC Schalke 04    €30M   €46K
     RW      <NAME>        88  28              Arsenal    €60M  €265K
    CAM    <NAME>        88  21  Bayer 04 Leverkusen    €22M   €49K
     LM      <NAME>        91  21      Manchester City  €34.5M  €125K
     CF   <NAME>        88  18  Bayer 04 Leverkusen     €8M   €25K<jupyter_text>![kroos](images/kroos.jpeg) 3.4 SpainHow about our 2010's winner?<jupyter_code>Spain = pd.DataFrame(np.array(get_summary_n(squad_list, squad_name, ['Spain'])).reshape(-1,4), columns = ['Nationality', 'Squad', 'Overall', 'Potential'])
Spain.set_index('Nationality', inplace = True)
Spain[['Overall', 'Potential']] = Spain[['Overall', 'Potential']].astype(float)

print (Spain)<jupyter_output>Squad  Overall  Potential
Nationality                             
Spain          3-4-3    86.27      88.82
Spain          4-4-2    86.45      88.73
Spain        4-3-1-2    86.55      88.09
Spain          4-3-3    86.64      89.00
Spain        4-2-3-1    86.64      89.00<jupyter_text>Well, Spain does best with either 4-3-3 or 4-2-3-1 for both current and potential rating. I'll choose 4-2-3-1 for the current squad and 4-3-3 for the potential squad.<jupyter_code>rating_4231_ESP_Overall, best_list_4231_ESP_Overall = get_best_squad_n(squad_4231_strict, 'Spain', 'Overall')
print('-Overall-')
print('Average rating: {:.1f}'.format(rating_4231_ESP_Overall))
print(best_list_4231_ESP_Overall)
rating_433_ESP_Potential, best_list_433_ESP_Potential = get_best_squad_n(squad_433_strict, 'Spain', 'Potential')
print('-Potential-')
print('Average rating: {:.1f}'.format(rating_433_ESP_Potential))
print(best_list_433_ESP_Potential)<jupyter_output>-Potential-
Average rating: 89.0
Position           Player Potential Age               Club   Value   Wage
     GK           De Gea        92  26  Manchester United  €64.5M  €215K
     RB  <NAME>        88  22            Arsenal    €21M   €91K
     CB     <NAME>        90  31     Real Madrid CF    €52M  €310K
     CB            Piqué        87  30       FC Barcelona  €37.5M  €240K
     LB      Azpilicueta        87  27            Chelsea  €37.5M  €160K
    CDM           Thiago        90  26   FC Bayern Munich  €70.5M  €225K
    CAM    <NAME>        88  20     Real Madrid CF  €16.5M  €105K
    CDM   <NAME>        87  23      Real Sociedad    €16M   €29K
     RM             Saúl        90  22    Atlético Madrid    €32M   €59K
     ST           Morata        88  24            Chelsea    €41M  €170K
     LW    <NAME>        92  21     Real Madrid CF    €46M  €175K<jupyter_text>![ramos](images/ramos.jpg) 3.5 EnglandAlthough having the best soccer league in Europe, England did not seem to do that well at the national level. Let's figure out their options for the upcoming World Cup:<jupyter_code>England = pd.DataFrame(np.array(get_summary_n(squad_list, squad_name, ['England'])).reshape(-1,4), columns = ['Nationality', 'Squad', 'Overall', 'Potential'])
England.set_index('Nationality', inplace = True)
England[['Overall', 'Potential']] = England[['Overall', 'Potential']].astype(float)

print (England)<jupyter_output>Squad  Overall  Potential
Nationality                             
England        3-4-3    82.64      87.18
England        4-4-2    82.64      87.27
England      4-3-1-2    82.27      86.73
England        4-3-3    82.73      87.36
England      4-2-3-1    82.36      87.36<jupyter_text>England should stick to 4-3-3 with their current squad and either 4-3-3 or 4-2-3-1 with their potential squad. Thus, I'll choose 4-3-3 and 4-2-3-1 respectively.<jupyter_code>rating_433_ENG_Overall, best_list_433_ENG_Overall = get_best_squad_n(squad_433_strict, 'England', 'Overall')
print('-Overall-')
print('Average rating: {:.1f}'.format(rating_433_ENG_Overall))
print(best_list_433_ENG_Overall)
rating_4231_ENG_Potential, best_list_4231_ENG_Potential = get_best_squad_n(squad_4231_strict, 'England', 'Potential')
print('-Potential-')
print('Average rating: {:.1f}'.format(rating_4231_ENG_Potential))
print(best_list_4231_ENG_Potential)<jupyter_output>-Potential-
Average rating: 87.4
Position                 Player Potential Age               Club   Value   Wage
     GK             <NAME>        87  24         Stoke City    €18M   €50K
    RWB  <NAME>        85  23          Liverpool    €20M  €105K
     CB               <NAME>        87  24            Everton    €21M   €91K
     CB              <NAME>        85  23    Manchester City  €14.5M  €105K
     LB                <NAME>        84  21  Manchester United    €14M   €91K
     CM               <NAME>        90  16  Manchester United   €975K    €9K
     CM                <NAME>        87  23  Tottenham Hotspur    €25M   €85K
     RM            <NAME>        89  19  Manchester United    €22M   €74K
    CAM             <NAME>        87  18  Tottenham Hotspur   €1.2M   €11K
     LM                <NAME>        90  21  Tottenham Hotspur    €43M  €115K
     ST                <NAME>        90  23  Tottenham Hotspur    €59M  €165K<jupyter_text>![kane](images/kane.jpg) 3.6 BrazilHaving won the World Cup the most times in history, the Samba team will no doubt be one of the top candidates for this summer in Russia.<jupyter_code>Brazil = pd.DataFrame(np.array(get_summary_n(squad_list, squad_name, ['Brazil'])).reshape(-1,4), columns = ['Nationality', 'Squad', 'Overall', 'Potential'])
Brazil.set_index('Nationality', inplace = True)
Brazil[['Overall', 'Potential']] = Brazil[['Overall', 'Potential']].astype(float)

print (Brazil)<jupyter_output>Squad  Overall  Potential
Nationality                             
Brazil         3-4-3    85.36      88.45
Brazil         4-4-2    84.73      88.00
Brazil       4-3-1-2    84.64      88.00
Brazil         4-3-3    85.45      88.73
Brazil       4-2-3-1    85.36      88.73<jupyter_text>As you can see, Brazil has similar options like England. I'll go with 4-3-3 for the current rating and 4-2-3-1 for the potential rating.<jupyter_code>rating_433_BRA_Overall, best_list_433_BRA_Overall = get_best_squad_n(squad_433_strict, 'Brazil', 'Overall')
print('-Overall-')
print('Average rating: {:.1f}'.format(rating_433_BRA_Overall))
print(best_list_433_BRA_Overall)
rating_4231_BRA_Potential, best_list_4231_BRA_Potential = get_best_squad_n(squad_4231_strict, 'Brazil', 'Potential')
print('-Potential-')
print('Average rating: {:.1f}'.format(rating_4231_BRA_Potential))
print(best_list_4231_BRA_Potential)<jupyter_output>-Potential-
Average rating: 88.7
Position         Player Potential Age                   Club   Value   Wage
     GK        Ederson        89  23        Manchester City    €26M   €87K
     RB     <NAME>        84  34    Paris Saint-Germain     €9M  €115K
     CB     Marquinhos        89  23    Paris Saint-Germain  €30.5M   €75K
     CB   <NAME>        88  32    Paris Saint-Germain    €34M  €175K
     LB        Marcelo        87  29         Real Madrid CF    €38M  €250K
    CDM       Casemiro        89  25         Real Madrid CF    €42M  €195K
    CDM        Fabinho        88  23              AS Monaco  €29.5M   €37K
     RM         Malcom        87  20  Girondins de Bordeaux  €24.5M   €47K
    CAM       Coutinho        89  25              Liverpool    €56M  €205K
     LW         Neymar        94  25    Paris Saint-Germain   €123M  €280K
     ST  <NAME>        92  20        Manchester City    €31M  €115K<jupyter_text>![neymar](images/neymar.jpg) 3.7 Argentina<NAME> is still waiting for the only trophy he hasn't gotten yet in his career. Can he carry Argentina to the top after going short in the final 4 years ago?<jupyter_code>Argentina = pd.DataFrame(np.array(get_summary_n(squad_list, squad_name, ['Argentina'])).reshape(-1,4), columns = ['Nationality', 'Squad', 'Overall', 'Potential'])
Argentina.set_index('Nationality', inplace = True)
Argentina[['Overall', 'Potential']] = Argentina[['Overall', 'Potential']].astype(float)

print (Argentina)<jupyter_output>Squad  Overall  Potential
Nationality                             
Argentina      3-4-3    84.27      87.36
Argentina      4-4-2    83.45      87.27
Argentina    4-3-1-2    83.55      86.73
Argentina      4-3-3    84.27      87.36
Argentina    4-2-3-1    84.00      87.09<jupyter_text>Both 3-4-3 and 4-3-3 fare very well for the current and potential ratings of Argentine players. For the sake of diversity, I'll choose 3-4-3 for their current squad and 4-3-3 for their future squad.<jupyter_code>rating_343_ARG_Overall, best_list_343_ARG_Overall = get_best_squad_n(squad_343_strict, 'Argentina', 'Overall')
print('-Overall-')
print('Average rating: {:.1f}'.format(rating_343_ARG_Overall))
print(best_list_343_ARG_Overall)
rating_433_ARG_Potential, best_list_433_ARG_Potential = get_best_squad_n(squad_433_strict, 'Argentina', 'Potential')
print('-Potential-')
print('Average rating: {:.1f}'.format(rating_433_ARG_Potential))
print(best_list_433_ARG_Potential)<jupyter_output>-Potential-
Average rating: 87.4
Position        Player Potential Age                  Club   Value   Wage
     GK      <NAME>        89  25         Real Sociedad  €25.5M   €28K
     RB      <NAME>        82  23         Independiente     €8M   €16K
     CB  <NAME>        86  26                 Milan    €27M  €105K
     CB    <NAME>        86  21  Zenit St. Petersburg    €10M   €36K
     LB       <NAME>        83  27     Manchester United    €21M  €130K
     CM      <NAME>        90  18         Independiente   €6.5M    €8K
     CM   <NAME>        86  21   Paris Saint-Germain    €10M   €48K
    CDM  <NAME>        86  20         VfB Stuttgart     €7M   €17K
     RW      <NAME>        93  30          FC Barcelona   €105M  €565K
     ST     <NAME>        93  23              Juventus    €79M  €215K
     LM    <NAME>        87  24       West Ham United  €24.5M   €95K<jupyter_text>![messi](images/messi.jpg) 3.8 BelgiumThe Red Devils has some of the best players in English Premier League, but can't never seem to make it far in the national level. Can Hazard and De Bruyne drive them far this time?<jupyter_code>Belgium = pd.DataFrame(np.array(get_summary_n(squad_list, squad_name, ['Belgium'])).reshape(-1,4), columns = ['Nationality', 'Squad', 'Overall', 'Potential'])
Belgium.set_index('Nationality', inplace = True)
Belgium[['Overall', 'Potential']] = Belgium[['Overall', 'Potential']].astype(float)

print (Belgium)<jupyter_output>Squad  Overall  Potential
Nationality                             
Belgium        3-4-3    83.91      86.55
Belgium        4-4-2    83.36      86.73
Belgium      4-3-1-2    83.09      86.09
Belgium        4-3-3    84.27      87.27
Belgium      4-2-3-1    84.00      87.00<jupyter_text>Again, 4-3-3 is the best formation for Belgium's both current and future squad.<jupyter_code>rating_433_BEL_Overall, best_list_433_BEL_Overall = get_best_squad_n(squad_433_strict, 'Belgium', 'Overall')
print('-Overall-')
print('Average rating: {:.1f}'.format(rating_433_BEL_Overall))
print(best_list_433_BEL_Overall)
rating_433_BEL_Potential, best_list_433_BEL_Potential = get_best_squad_n(squad_433_strict, 'Belgium', 'Potential')
print('-Potential-')
print('Average rating: {:.1f}'.format(rating_433_BEL_Potential))
print(best_list_433_BEL_Potential)<jupyter_output>-Potential-
Average rating: 87.3
Position           Player Potential Age               Club   Value   Wage
     GK      T. Courtois        92  25            Chelsea    €59M  €190K
     RB         T. Foket        79  22           KAA Gent   €5.5M   €19K
     CB  T. Alderweireld        87  28  Tottenham Hotspur  €40.5M  €165K
     CB    <NAME>        86  22     RSC Anderlecht    €15M   €25K
     LB        <NAME>        83  22              Lazio    €10M   €39K
     CM          <NAME>        84  18                PSV   €1.3M    €3K
    CAM     <NAME>        90  20          AS Monaco  €23.5M   €35K
    CAM    <NAME>        86  29               Roma  €42.5M  €130K
     RM     <NAME>        92  26    Manchester City    €83M  €285K
     ST        <NAME>        90  24  Manchester United    €59M  €210K
     LW        <NAME>        91  26            Chelsea  €90.5M  €295K<jupyter_text>![de-bruyne](images/de-bruyne.jpg) 3.9 - PortugalThe winner of Euro 2016 and the best player in the world 3 times in a row, <NAME>, has a real chance in this tournament as well.<jupyter_code>Portugal = pd.DataFrame(np.array(get_summary_n(squad_list, squad_name, ['Portugal'])).reshape(-1,4), columns = ['Nationality', 'Squad', 'Overall', 'Potential'])
Portugal.set_index('Nationality', inplace = True)
Portugal[['Overall', 'Potential']] = Portugal[['Overall', 'Potential']].astype(float)

print (Portugal)<jupyter_output>Squad  Overall  Potential
Nationality                             
Portugal       3-4-3    83.00      87.00
Portugal       4-4-2    83.00      87.27
Portugal     4-3-1-2    82.82      86.55
Portugal       4-3-3    83.45      87.45
Portugal     4-2-3-1    83.45      87.27<jupyter_text>OK, I'll go with 4-2-3-1 for current rating and 4-3-3 for potential rating of Portugal.<jupyter_code>rating_4231_POR_Overall, best_list_4231_POR_Overall = get_best_squad_n(squad_4231_strict, 'Portugal', 'Overall')
print('-Overall-')
print('Average rating: {:.1f}'.format(rating_4231_POR_Overall))
print(best_list_4231_POR_Overall)
rating_433_POR_Potential, best_list_433_POR_Potential = get_best_squad_n(squad_433_strict, 'Portugal', 'Potential')
print('-Potential-')
print('Average rating: {:.1f}'.format(rating_433_POR_Potential))
print(best_list_433_POR_Potential)<jupyter_output>-Potential-
Average rating: 87.5
Position             Player Potential Age                Club   Value   Wage
     GK           <NAME>        86  26  Olympique Lyonnais  €22.5M   €60K
     RB      <NAME>        87  23        FC Barcelona  €20.5M  €125K
     CB               Pepe        86  34         Beşiktaş JK  €13.5M   €94K
     CB       <NAME>        85  23       Villarreal CF  €12.5M   €27K
     LB        <NAME>        83  22              Fulham   €8.5M   €11K
     CM   <NAME>        86  25         Sporting CP  €27.5M   €21K
    CAM         <NAME>        88  24               Inter    €34M   €70K
    CAM        <NAME>        88  23        FC Barcelona    €30M  €150K
     RM     <NAME>        91  22     Manchester City  €43.5M  €165K
     ST  <NAME>        94  32      Real Madrid CF  €95.5M  €565K
     LM     <NAME>        88  22         Sporting CP    €25M   €20K<jupyter_text>![ronaldo](images/ronaldo.jpg) 3.10 - UruguayUruguay has the 2 best strikers in Europe: Suarez & Cavani. Can they perform this time?<jupyter_code>Uruguay = pd.DataFrame(np.array(get_summary_n(squad_list, squad_name, ['Uruguay'])).reshape(-1,4), columns = ['Nationality', 'Squad', 'Overall', 'Potential'])
Uruguay.set_index('Nationality', inplace = True)
Uruguay[['Overall', 'Potential']] = Uruguay[['Overall', 'Potential']].astype(float)

print (Uruguay)<jupyter_output>Squad  Overall  Potential
Nationality                             
Uruguay        3-4-3    80.64      84.91
Uruguay        4-4-2    81.09      85.27
Uruguay      4-3-1-2    81.09      84.73
Uruguay        4-3-3    80.18      84.91
Uruguay      4-2-3-1    79.82      84.27<jupyter_text>Fantastic, Uruguay does best with a 4-3-1-2 for current rating and 4-4-2 for future rating.<jupyter_code>rating_4312_URG_Overall, best_list_4312_URG_Overall = get_best_squad_n(squad_4312_strict, 'Uruguay', 'Overall')
print('-Overall-')
print('Average rating: {:.1f}'.format(rating_4312_URG_Overall))
print(best_list_4312_URG_Overall)
rating_442_URG_Potential, best_list_442_URG_Potential = get_best_squad_n(squad_442_strict, 'Uruguay', 'Potential')
print('-Potential-')
print('Average rating: {:.1f}'.format(rating_442_URG_Potential))
print(best_list_442_URG_Potential)<jupyter_output>-Potential-
Average rating: 85.3
Position       Player Potential Age                       Club   Value   Wage
     GK   <NAME>        82  31             Galatasaray SK  €13.5M   €57K
     RB  <NAME>        82  20           Sevilla Atlético   €1.8M    €3K
     CB     <NAME>        88  31            Atlético Madrid    €40M  €125K
     CB   <NAME>        87  22            Atlético Madrid  €28.5M   €53K
    LWB  <NAME>        85  19                River Plate   €3.4M    €7K
     RM  <NAME>        85  18  RC Deportivo de La Coruña   €3.6M   €44K
     CM    <NAME>        85  21               Boca Juniors   €3.5M   €11K
     CM  <NAME>        83  21                  Sampdoria    €10M   €26K
     LM    <NAME>        82  24                      Genoa  €13.5M   €30K
     ST    <NAME>        92  30               FC Barcelona    €97M  €510K
     ST    E. Cavani        87  30        Paris Saint-Germain  €48.5M  €160K<jupyter_text>![](images/cavani.jpg) 3.11 - CroatiaWell, I'm a big fan of Modric and Rakitic. Needless to say about their winning habits?<jupyter_code>Croatia = pd.DataFrame(np.array(get_summary_n(squad_list, squad_name, ['Croatia'])).reshape(-1,4), columns = ['Nationality', 'Squad', 'Overall', 'Potential'])
Croatia.set_index('Nationality', inplace = True)
Croatia[['Overall', 'Potential']] = Croatia[['Overall', 'Potential']].astype(float)

print (Croatia)<jupyter_output>Squad  Overall  Potential
Nationality                             
Croatia        3-4-3    80.55      83.00
Croatia        4-4-2    80.82      83.00
Croatia      4-3-1-2    81.27      83.64
Croatia        4-3-3    81.64      83.91
Croatia      4-2-3-1    81.64      83.64<jupyter_text>Dope, Croatia is superior with a 4-2-3-1 using current form and 4-3-3 using potential form.<jupyter_code>rating_4231_CRO_Overall, best_list_4231_CRO_Overall = get_best_squad_n(squad_4231_strict, 'Croatia', 'Overall')
print('-Overall-')
print('Average rating: {:.1f}'.format(rating_4231_CRO_Overall))
print(best_list_4231_CRO_Overall)
rating_433_CRO_Potential, best_list_433_CRO_Potential = get_best_squad_n(squad_433_strict, 'Croatia', 'Potential')
print('-Potential-')
print('Average rating: {:.1f}'.format(rating_433_CRO_Potential))
print(best_list_433_CRO_Potential)<jupyter_output>-Potential-
Average rating: 83.9
Position      Player Potential Age                 Club   Value   Wage
     GK  <NAME>        85  32            AS Monaco    €22M   €46K
     RB   <NAME>        84  21  Bayer 04 Leverkusen    €10M   €36K
     CB   <NAME>        83  27            Liverpool  €17.5M  €110K
     CB  <NAME>        82  31     Lokomotiv Moscow    €15M   €54K
     LB    <NAME>        76  23          KV Oostende   €2.7M    €9K
    CDM   <NAME>        89  31       Real Madrid CF    €57M  €340K
    CDM  <NAME>        88  23       Real Madrid CF    €30M  €150K
     CM  <NAME>        87  29         FC Barcelona  €48.5M  €275K
     RM  <NAME>        82  19        VfB Stuttgart   €3.1M   €21K
     ST  <NAME>        81  29                Milan    €18M   €84K
     LW    <NAME>        86  22             Juventus  €12.5M   €89K<jupyter_text>![](images/modric.jpg) 4 - Final ComparisonOk, let's make some comparison between these 10 line-ups with the current rating of players for these strongest contenders for World Cup 2018.<jupyter_code>teams = ('France', 'Germany', 'Spain', 'England', 'Brazil', 'Argentina', 'Belgium', 'Portugal', 'Uruguay', 'Croatia')
index = np.arange(len(teams))
average_overall = [84.6, 86.3, 86.6, 82.7, 85.5, 84.3, 84.3, 83.5, 81.1, 81.6]

plt.figure(figsize=(16,8))
plt.barh(index, average_overall, align='center', alpha=0.5)
plt.yticks(index, teams, fontsize=20)
plt.ylabel('National Teams', fontsize=25)
plt.xlabel('Average Overall', fontsize=25)
plt.title('Average Overall Rating of Players', fontsize=30, fontweight='bold', y=1.05,)
 
plt.show()
total_value = [446.5, 502, 484.5, 298.5, 433, 382, 440.5, 323, 283.5, 244.9]

plt.figure(figsize=(16,8))
plt.barh(index, total_value, align='center', alpha=0.5, color='red')
plt.yticks(index, teams, fontsize=20)
plt.ylabel('National Teams', fontsize=25)
plt.xlabel('Total Value in Million Euros', fontsize=25)
plt.title('Total Value of Players', fontsize=30, fontweight='bold', y=1.05,)
 
plt.show()
average_wage = [141, 188, 228, 119, 167, 151, 166, 118, 99, 110]

plt.figure(figsize=(16,8))
plt.barh(index, average_wage, align='center', alpha=0.5, color='green')
plt.yticks(index, teams, fontsize=20)
plt.ylabel('National Teams', fontsize=25)
plt.xlabel('Average Wages in Thousand Euros', fontsize=25)
plt.title('Average Wages of Players', fontsize=30, fontweight='bold', y=1.05,)
 
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12625230014312003, 'fraction_numerical': 0.07255673686362707, 'mean_word_length': 2.7653002309468824, 'pattern_counts': {'":': 0, '<': 300, '<?xml version=': 0, '>': 300, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '40', 'dir': 'jupyter-structured-clean-dedup', 'id': '374791', 'license': 'MIT', 'n_tokens_mistral': 15775, 'n_tokens_neox': 13707, 'n_words': 3268, 'path': 'Ideal_Team_Lineup_World_Cup_2018.ipynb', 'repo_name': 'anuragv1729/world-cup-2018-master', 'size': '39563'}