text_plain_output_1.png image_output_1.png
import matplotlib.pyplot as plt

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import seaborn as sns

players = pd.read_csv('/kaggle/input/fifa-world-cup/WorldCupPlayers.csv')
matches = pd.read_csv('/kaggle/input/fifa-world-cup/WorldCupMatches.csv')
cups = pd.read_csv('/kaggle/input/fifa-world-cup/WorldCups.csv')

matches = matches.dropna()

partidos_por_anio = matches[['Year', 'MatchID']].dropna().astype('Int64')

def cantidad_goles(texto):
    return texto.count('G') - texto.count('OG')

jugadores_goles = players[['MatchID', 'Player Name', 'goles']]

goles = pd.merge(jugadores_goles, partidos_por_anio, on='MatchID', how='inner')
goles

inicio = goles.groupby('Player Name').agg({'Year': 'min'})
inicio = inicio.to_dict()['Year']

def min_goles(texto):
    eventos = texto.split("' ")
    goles = [e.replace("'", '') for e in eventos if e and e[0] == 'G']
    return [int(g[1:]) for g in goles]

plt.xlim((0, 120))
plt.yticks([])

matches.groupby(['Home Team Name', 'Year']).agg({'Home Team Goals': 'mean'})

matches.groupby(['Away Team Name', 'Year']).agg({'Away Team Goals': 'mean'})

home_goals = matches[['Home Team Name', 'Year', 'Home Team Goals']].rename(columns={'Home Team Name': 'Team Name', 'Home Team Goals': 'Goals'})

away_goals = matches[['Away Team Name', 'Year', 'Away Team Goals']].rename(columns={'Away Team Name': 'Team Name', 'Home Team Goals': 'Goals'})

goals = pd.concat([home_goals, away_goals], ignore_index=True)

goals.groupby(['Team Name', 'Year']).agg({'Goals': 'mean'})

sns.heatmap(goals.pivot_table(values='Goals', index='Team Name', columns='Year', aggfunc='mean').fillna(0))