Instructions:
# This Python 3 environment comes with many helpful analytics libraries installed
# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python
# For example, here's several helpful packages to load
import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
# Input data files are available in the read-only "../input/" directory
# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory
import os
for dirname, _, filenames in os.walk('/kaggle/input'):
for filename in filenames:
print(os.path.join(dirname, filename))
# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using "Save & Run All"
# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session
df = pd.read_csv("/kaggle/input/international-football-results-from-1872-to-2017/results.csv")
df.head()
dg_home = df.groupby('home_team').aggregate(["describe"])
type(dg_home)
df_group_home = df.groupby('home_team')
italy_home = df_group_home.get_group("Italy")
italy_home[italy_home.away_team == "Brazil"]
df_group_away = df.groupby('away_team')
italy_away = df_group_away.get_group("Italy")
italy_away[italy_away.home_team == "Brazil"]
italy_vs_brazil = pd.concat([ df[(df.home_team == 'Brazil') & (df.away_team == 'Italy')],
df[(df.home_team == 'Italy') & (df.away_team == 'Brazil')]],
axis=0).sort_values('date')
italy_vs_brazil.head()
def get_winner(x):
if x["home_score"] > x["away_score"]:
return x["home_team"]
if x["home_score"] < x["away_score"]:
return x["away_team"]
return "Draw"
italy_vs_brazil["winner"] = italy_vs_brazil.apply(lambda row: get_winner(row), axis=1)
italy_vs_brazil.head()
cols = italy_vs_brazil.columns.to_list()
cols.insert(3, "winner")
cols.pop()
cols
italy_vs_brazil = italy_vs_brazil.reindex(columns = cols)
italy_vs_brazil.head()