Learn data science and machine learning by building real-world projects on Jovian
In [49]:
# Importing the Libraries

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
In [2]:
# Reading the data

fifa = pd.read_csv('data.csv')
pd.set_option('display.max_columns', None)
fifa.head()
Out[2]:
In [3]:
# Removing columns

fifa.drop(fifa.loc[:,'Unnamed: 0':'ID'], axis=1, inplace=True)   # --> 1

In [4]:
fifa.drop(['Photo','Flag','Club Logo','Special','Work Rate','Body Type','Real Face'], axis=1, inplace=True)
In [5]:
fifa.drop(fifa.loc[:,'LS':'RB'], axis=1, inplace=True)
In [6]:
fifa.head(8)
Out[6]:
In [7]:
fifa.shape
Out[7]:
(18207, 54)
In [8]:
# Inspecting the null values

fifa.isnull().sum()
Out[8]:
Name                            0
Age                             0
Nationality                     0
Overall                         0
Potential                       0
Club                          241
Value                           0
Wage                            0
Preferred Foot                 48
International Reputation       48
Weak Foot                      48
Skill Moves                    48
Position                       60
Jersey Number                  60
Joined                       1553
Loaned From                 16943
Contract Valid Until          289
Height                         48
Weight                         48
Crossing                       48
Finishing                      48
HeadingAccuracy                48
ShortPassing                   48
Volleys                        48
Dribbling                      48
Curve                          48
FKAccuracy                     48
LongPassing                    48
BallControl                    48
Acceleration                   48
SprintSpeed                    48
Agility                        48
Reactions                      48
Balance                        48
ShotPower                      48
Jumping                        48
Stamina                        48
Strength                       48
LongShots                      48
Aggression                     48
Interceptions                  48
Positioning                    48
Vision                         48
Penalties                      48
Composure                      48
Marking                        48
StandingTackle                 48
SlidingTackle                  48
GKDiving                       48
GKHandling                     48
GKKicking                      48
GKPositioning                  48
GKReflexes                     48
Release Clause               1564
dtype: int64
In [9]:
# Removing null values from Club col.

fifa = fifa[~fifa.Club.isnull()]
In [10]:
# Removing the null values from Position col.

fifa = fifa[~fifa.Position.isnull()]
In [11]:
# Removing the Loaned From col.

fifa.drop(['Loaned From'], axis=1, inplace=True)
In [12]:
# Checking the Joined col.

fifa.Joined.describe()
Out[12]:
count           16654
unique           1736
top       Jul 1, 2018
freq             1538
Name: Joined, dtype: object
In [13]:
# Replacing the null values in Joined col.

fifa.Joined.fillna('Jul 1, 2018', inplace=True)
In [14]:
# Updating the Value col.

fifa.Value = fifa.Value.str.replace('€', '')
In [15]:
# Converting the Value col.

fifa.Value = fifa.Value.replace({'K':'*1e3', 'M':'*1e6'}, regex=True).map(pd.eval)
In [16]:
# Converting to millions

Value_M = fifa.Value.apply(lambda x: x/1000000)
fifa.insert(loc=7, column='Value M', value=Value_M)
In [17]:
# Updating the Wage col.

fifa.Wage = fifa.Wage.str.replace('€', '')
In [18]:
# Converting the Wage col.

fifa.Wage = fifa.Wage.replace({'K':'*1e3'}, regex=True).map(pd.eval)

In [19]:
Wage_T= fifa.Wage.apply(lambda x: x/1000)
fifa.insert(loc=8, column='Wage T', value=Wage_T)
In [20]:
fifa['Release Clause'] = fifa['Release Clause'].str.replace('€', '')
In [21]:
# Filling the null values in Release Clause

fifa['Release Clause'] = fifa['Release Clause'].fillna(0)
In [22]:
fifa['Release Clause'] = fifa['Release Clause'].replace({'K':'*1e3', 'M':'*1e6'}, regex=True).map(pd.eval)
In [23]:
Release_Clause_M = fifa['Release Clause'].apply(lambda x: x/1000000)
fifa.insert(loc=8, column='Release Clause M', value=Release_Clause_M)
In [24]:
fifa.drop(['Value','Wage','Release Clause'], axis=1, inplace=True)
In [25]:
# Processing the height col.

Height_cms=[]

for i in list(fifa.Height.values):
    Height_cms.append((float(str(i)[0])*12.0 + float(str(i)[2:]))*2.54)
    
fifa.insert(loc=18, column='Height_cms', value=Height_cms)
In [26]:
fifa.drop(['Height'], axis=1, inplace=True)
In [27]:
# Changing the Weight col.

fifa.Weight = fifa.Weight.str.replace('lbs','')
In [28]:
fifa.Weight = fifa.Weight.astype('int64')
In [29]:
fifa.Weight = fifa.Weight.apply(lambda x: x*0.45)
In [30]:
# Changing the Jersey Number to int

fifa['Jersey Number'] = fifa['Jersey Number'].astype('int')
In [31]:
fifa.head()
Out[31]:
In [32]:
# Q1. Which player has highest number of short passes.

fifa[fifa.ShortPassing==fifa.ShortPassing.max()][['Name','Club','ShortPassing']]
Out[32]:
In [33]:
# Q2. Low Age -- > Most Valuable player

fifa_age = fifa[fifa.Age <= 23][['Name','Age','Value M']]
fifa_age[fifa_age['Value M']==fifa_age['Value M'].max()]
Out[33]:
In [46]:
plt.boxplot(fifa.Age)
plt.show()
Notebook Image
In [43]:
fifa[fifa.Age>=45]
Out[43]:
In [48]:
plt.boxplot(fifa.Height_cms)
plt.show()
Notebook Image
In [52]:
plt.figure(figsize=[10,12])

sns.distplot(fifa.Height_cms)
plt.show()
Notebook Image
In [ ]: