image_output_1.png
import matplotlib.pyplot as plt

import numpy as np

import pandas as pd

import re

import seaborn as sns

df = pd.read_csv('../input/fifa19/data.csv')

percent_null = []
n_col = df.columns
for col in n_col:
    percent_null.append(df[col].isnull().sum() / len(df[col]) * 100)
df_missing = pd.DataFrame(percent_null, index=df.columns, columns=['percent_missing'])
df_missing = df_missing.reset_index().rename({'index': 'column_name'}, axis=1)
df_missing = df_missing[df_missing['percent_missing'] > 0].sort_values(by='percent_missing', ascending=False)
clr = ['steelblue' if percent > 10 else 'skyblue' for percent in df_missing['percent_missing']]

def make_distplot(data,title):
    fig,ax=plt.subplots(figsize=(10,5))
    ax.set_title(title)
    sns.distplot(data,bins=30)

def horizontal_bar(data,x,y,title):
    fig,ax=plt.subplots(figsize=(10,5))
    sns.barplot(data=data,x=x,y=y,color='steelblue')
    ax.set_xlabel(x)
    ax.set_ylabel(y)
    ax.set_title(title)

def mil_to_thousand(data):
    regex = '[-+]?(\\d*\\.?\\d+)'
    data = str(data)
    size = len(data)
    if data[size - 1] == 'M':
        data = re.findall(regex, data)
        data = np.asarray(data).astype('float64')
        data = data * 1000
    else:
        data = re.findall(regex, data)
        data = np.asarray(data).astype('float64')
    return data

df['Release Clause'] = df['Release Clause'].apply(lambda x: mil_to_thousand(x))
df = df.explode('Release Clause')
df['Release Clause'] = df['Release Clause']
players_rc = df[['Name', 'Release Clause']].sort_values(by='Release Clause', ascending=False)[:20]
horizontal_bar(players_rc, 'Release Clause', 'Name', 'Players with Highest Release Clause (in thousand euros)')

df['Value'] = df['Value'].apply(lambda x: mil_to_thousand(x))
df = df.explode('Value')
df['Value'] = df['Value'].astype('float')
pos_value = df.groupby('Position')['Value'].sum().sort_values(ascending=False).reset_index()[:20]
horizontal_bar(pos_value, 'Value', 'Position', 'Total Value in Every Position (in thousand euros)')

pos_value = df.groupby('Position')['Value'].median().sort_values(ascending=False).reset_index()[:20]
horizontal_bar(pos_value, 'Value', 'Position', 'Median Value in Every Position (in thousand euros)')