<jupyter_start><jupyter_text>Queries / Questions being investigated through the Data,As a football fan, I'm interested in exploring FIFA-2019 Complete Dataset of players. I will be trying to answer the following questionnaires through the data analysis I am gonna do here : Question 1: List of 25 nations in Decending Order, having more number of Soccer Players according the latest FIFA-2019 datasets available on the Kaggle website. Question 2: Listing 10 clubs in descending order, with the highest total player market value and the highest average player wage.  Question 3: AGE-WISE distribution of the players present in FIFA-2019. Question 4: Selection of the best Squad according to the preferref position of the players. Question 5: FInding the correlation between features such as Age, Overall, Potential, Position, Club, Nationality, Special vs Value/Wage.Understanding these questions may provide some advice to the Football Club Manager, no matter in Video Game, or in real Professional football.  Data UnderstandingThrough this project, we will use FIFA-2019 Complete Player Dataset from kaggle. For this project, I will use the data2019.csv which contains all the information of the Players of FIFA-2019. Here we go.<jupyter_code># Read in the Dataset file "data2019" downloaded from Kaggle.
data2019 = pd.read_csv('./data2019.csv')
data2019.head()
# Basic Description of the dataset
data2019.describe()
# Description of the datatypes of the dataset
data2019.info()
#Calculate the number of rows & Columns in the dataset

num_rows = data2019.shape[0] 
num_cols = data2019.shape[1]
print("Row Number: {}".format(num_rows))
print("Column Number: {}".format(num_cols))<jupyter_output>Row Number: 18207
Column Number: 89<jupyter_text>Data Preparation / PreprocessingWe gonna do the following steps as a part of Data Preparation：1. Check columns having missing values.2. Drop unused columns3. Conversion of string values into numbers for Value & Wage.4. One-Hot Encoding for Categorical variables such as Club, Nationality, Preferred Positions.<jupyter_code># Data Preparation Step 1: Check whether any column has missing values
columns_with_missing_values = set(data2019.columns[data2019.isnull().mean()!=0])
print(columns_with_missing_values)<jupyter_output>{'International Reputation', 'Interceptions', 'Real Face', 'RCM', 'LDM', 'LCB', 'RB', 'Crossing', 'GKPositioning', 'RAM', 'ShotPower', 'Body Type', 'RF', 'Jumping', 'ST', 'Weight', 'CF', 'CAM', 'RM', 'Club', 'RDM', 'LongPassing', 'BallControl', 'Acceleration', 'LF', 'Penalties', 'Vision', 'StandingTackle', 'Release Clause', 'Work Rate', 'Preferred Positions', 'Strength', 'Positioning', 'Height', 'Aggression', 'LW', 'Dribbling', 'Skill Moves', 'Jersey Number', 'Marking', 'Contract Valid Until', 'GKDiving', 'LCM', 'Joined', 'Composure', 'Weak Foot', 'LS', 'LAM', 'Curve', 'SprintSpeed', 'Reactions', 'Finishing', 'RS', 'Stamina', 'CDM', 'RWB', 'Balance', 'Loaned From', 'RW', 'LongShots', 'HeadingAccuracy', 'GKKicking', 'ShortPassing', 'CM', 'Agility', 'Preferred Foot', 'LWB', 'FKAccuracy', 'CB', 'RCB', 'Volleys', 'GKHandling', 'GKReflexes', 'LB', 'SlidingTackle', 'LM'}<jupyter_text>It can be observed that most of the columns with missing values are the ratings at all positions, because of Goalkeepers.  And these columns except Club, have not been used in my questions. However for Club, it can be said that a player may not belong to any club for the moment. Therefore, any club insterested in him may sign this player without paying any transfer fees.<jupyter_code># Data Preparation Step 2: Dropping columns which will not be used in this project
data2019.drop('Photo',     axis = 1,inplace=True)
data2019.drop('Flag',      axis = 1,inplace=True)
data2019.drop('Club Logo', axis = 1,inplace=True)
data2019.drop('ID',        axis = 1,inplace=True)
data2019.head()
# Function to convert string values into numbers

def str2number(amount):
    """
    This function perform convertion from amount values in string type to float type numbers
    
    Parameter:
    amount(str): Amount values in string type with M & K as Abbreviation for Million and Thousands
    
    Returns:
    float: A float number represents the numerical value of the input parameter amount(str)
    """
    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:])
# Data Preparation Step 3: Conversion of string values into numbers for Value & Wage

data2019['Wage_Number']  = data2019['Wage'].map(lambda x: str2number(x))
data2019['Value_Number'] = data2019['Value'].map(lambda x: str2number(x))
# Data Preparation Step 4: One-Hot Encoding for Categorical variables such as Club, Nationality, Preferred Positions.

le = LabelEncoder()
data2019['Club_onehot_encode']               = le.fit_transform(data2019['Club'].astype(str))
data2019['Nationality_onehot_encode']        = le.fit_transform(data2019['Nationality'].astype(str))
data2019['Preferred Positions_onehot_encode'] = le.fit_transform(data2019['Preferred Positions'].astype(str))<jupyter_output><empty_output><jupyter_text>Solution to the queries raised above: Since data preprocessing/preparation is over, we may try to the answer the questions as raised above:<jupyter_code># Question 1: List of 25 nations in Decending Order, having more number of Soccer Players according the latest FIFA-2019 datasets available on the Kaggle website.
nationality_vals = data2019.Nationality.value_counts()
print(nationality_vals.head(25))

(nationality_vals.head(20)/data2019.shape[0]).plot(kind="bar");
plt.title("Top 25 FIFA-2019 Players Nationality Distribution(In %age)");<jupyter_output>England                1662
Germany                1198
Spain                  1072
Argentina               937
France                  914
Brazil                  827
Italy                   702
Colombia                618
Japan                   478
Netherlands             453
Sweden                  397
China PR                392
Chile                   391
Republic of Ireland     368
Mexico                  366
United States           353
Poland                  350
Norway                  341
Saudi Arabia            340
Denmark                 336
Korea Republic          335
Portugal                322
Turkey                  303
Austria                 298
Scotland                286
Name: Nationality, dtype: int64<jupyter_text>We can derive from the above result and plot that England, Germany and Spain are the top 3 nations having more number of players in FIFA-2019. France is at 5th position which is also an European nation. It can be justified as Barclays Premier League, Bundesliga, La Liga and Ligue 1 are among the Five Football Leagues in Europe. These leagues represent the best football in Europe and even in the world, attracting many football stars and often guiding the new direction of football development. The 4th & 6th ranking is Agentina and Brazil which have the most gifted football players in the world. It’s clear that most players are between 21–25 years old. It’s reasonable as this age group is the best years of athletes. Players younger than that may not have the enough skills and experiences and also may not have the chance to prove themself on the football field yet. Players elder than 30 may already retire from the football filed. Thus the number for players elder than 30 drops with the growth of age.<jupyter_code># Question 2: Listing 10 clubs in descending order, with the highest total player market value and the highest average player wage.
Value_Wage_DF = data2019[["Name", "Club", "Value_Number", "Wage_Number"]]
Value_Wage_DF.head(10)
# Top 10 clubs with the highest average wage
Value_Wage_DF.groupby("Club")["Wage_Number"].mean().sort_values(ascending=False).head(10).plot(kind="bar");
plt.title("Top 10 clubs with the highest average wage");<jupyter_output><empty_output><jupyter_text>As observed from plot, Real Madrid, FC Barcelona & Juventus are the top3 clubs who is paying highest average wage to its players. High paying in wage also help these clubs to attract the most valuable players to play for the clubs.<jupyter_code># Top 10 clubs with the highest total player market value
Value_Wage_DF.groupby("Club")["Value_Number"].sum().sort_values(ascending=False).head(10).plot(kind="bar");
plt.title("Top 10 clubs with the highest total player market Value");
# Question 3: AGE-WISE distribution of the players present in FIFA-2019.
age_vals = data2019.Age.value_counts()
print(age_vals.head(20))

(age_vals.head(20)/data2019.shape[0]).plot(kind="bar");
plt.title("FIFA-2019 Players Age Distribution (In %age)");<jupyter_output>21    1423
26    1387
24    1358
22    1340
23    1332
25    1319
20    1240
27    1162
28    1101
19    1024
29     959
30     917
18     732
31     707
32     574
33     408
34     404
17     289
35     196
36     127
Name: Age, dtype: int64<jupyter_text>It can be clearly understood from the plot that the most players are between 21–25 years old. People at this age group are the best years of athletes in lifetime. Players younger than that may not have enough skills and experiences, whereas players above that might have already retired from the football. So, there is a drop in those age groups.<jupyter_code># Question 4: Selection of the best Squad according to the preferref position of the players.
BestSquad_DF = data2019[['Name', 'Age', 'Overall', 'Potential', 'Preferred Positions']]
BestSquad_DF.head(5)<jupyter_output><empty_output><jupyter_text>On the pattern of video game FIFA-2019, human player selects expert players for each position to win the matches. Likewise, also includes a game mode to ask gamer to play as a role of a football manager. Based on FIFA-2019 dataset, we will try to find the best squad according to the preferred positions of the star players. Here, I have considered two best squads such as: Formation 4–3–3 and Formation 3–4–1–2.<jupyter_code>def find_best_squad(position):
    """
    This function perform selection of the player with highest Overall Value for each provided position
    
    Parameter:
    position(str): a particular position of a certain footbal formation
    
    Returns:
    Position: The position from Input Parameter
    Player:   The Best Player Name for this Position
    Overall:  The Overall Value for this Best Player
    """
    BestSquad_DF_copy = BestSquad_DF.copy()
    BestSquad = []
    for i in position:
        BestSquad.append([i,BestSquad_DF_copy.loc[[BestSquad_DF_copy[BestSquad_DF_copy['Preferred Positions'] == i]['Overall'].idxmax()]]['Name'].to_string(index = False), BestSquad_DF_copy[BestSquad_DF_copy['Preferred Positions'] == i]['Overall'].max()])
        BestSquad_DF_copy.drop(BestSquad_DF_copy[BestSquad_DF_copy['Preferred Positions'] == i]['Overall'].idxmax(), inplace = True)

    return pd.DataFrame(np.array(BestSquad).reshape(11,3), columns = ['Position', 'Player', 'Overall']).to_string(index = False)
# Formation 4-3-3
squad_Formation433 = ['GK', 'LB', 'CB', 'CB', 'RB', 'LM', 'CDM', 'RM', 'LW', 'ST', 'RW']
print ('Best Squad of Formation 4-3-3')
print (find_best_squad(squad_Formation433))
# Formation 3-4-1-2
squad_Formation3412 = ['GK', 'CB', 'CB', 'CB', 'LM', 'CM', 'CM', 'RM', 'CAM', 'ST', 'ST']
print ('Best Squad of Formation 3-4-1-2')
print (find_best_squad(squad_Formation3412))
# Question 5: Finding the correlation between features such as Age, Overall, Potential, Position, Club, Nationality, Special vs Value/Wage.
Correlation_DF = data2019[['Name', 'Age', 'Overall', 'Potential', 'Preferred Positions_onehot_encode', 'Club_onehot_encode', 'Nationality_onehot_encode', 'Special', 'Value_Number', 'Wage_Number']]

Correlation_DF.corr()
colormap = plt.cm.inferno
plt.figure(figsize=(16,12))
plt.title('Correlation between Age, Overall, Potential, Position, Club, Nationality, Special vs Value/Wage', y=1.05, size=15)
sns.heatmap(Correlation_DF.corr(),linewidths=0.1,vmax=1.0, 
            square=True, cmap=colormap, linecolor='white', annot=True)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09683810781804672, 'fraction_numerical': 0.04367208783951127, 'mean_word_length': 4.393588601959038, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '423357', 'license': 'CNRI-Python', 'n_tokens_mistral': 3881, 'n_tokens_neox': 3411, 'n_words': 1367, 'path': '.ipynb_checkpoints/Write A Data Science Blog Post - FIFA 2019 Players-checkpoint.ipynb', 'repo_name': 'manish8917/Udacity-Write-a-Data-Science-Blog-Post-master', 'size': '12113'}