From df817332717e944e8e0f68b4c2d65e23257000bb Mon Sep 17 00:00:00 2001 From: Pelumi Adeboye Date: Sun, 16 Jun 2024 23:05:10 +0100 Subject: [PATCH] Add files via upload --- Uefa_euros_fixture.csv | 52 + Uefa_euros_historical_data.csv | 317 ++++ clean_Uefa_euros_fixture.csv | 52 + clean_Uefa_euros_historical_data.csv | 317 ++++ data_cleaning.ipynb | 1247 ++++++++++++++ dict_table | Bin 0 -> 4457 bytes get_pastresults.py | 38 + get_tables.ipynb | 329 ++++ predict_euros.ipynb | 2268 ++++++++++++++++++++++++++ third_place_fixtures.csv | 16 + 10 files changed, 4636 insertions(+) create mode 100644 Uefa_euros_fixture.csv create mode 100644 Uefa_euros_historical_data.csv create mode 100644 clean_Uefa_euros_fixture.csv create mode 100644 clean_Uefa_euros_historical_data.csv create mode 100644 data_cleaning.ipynb create mode 100644 dict_table create mode 100644 get_pastresults.py create mode 100644 get_tables.ipynb create mode 100644 predict_euros.ipynb create mode 100644 third_place_fixtures.csv diff --git a/Uefa_euros_fixture.csv b/Uefa_euros_fixture.csv new file mode 100644 index 0000000..34de47e --- /dev/null +++ b/Uefa_euros_fixture.csv @@ -0,0 +1,52 @@ +home,score,away,year +Germany ,Match 1, Scotland,2024 +Hungary ,Match 2,  Switzerland,2024 +Germany ,Match 14, Hungary,2024 +Scotland ,Match 13,  Switzerland,2024 +Switzerland ,Match 25, Germany,2024 +Scotland ,Match 26, Hungary,2024 +Spain ,Match 3, Croatia,2024 +Italy ,Match 4, Albania,2024 +Croatia ,Match 15, Albania,2024 +Spain ,Match 16, Italy,2024 +Albania ,Match 27, Spain,2024 +Croatia ,Match 28, Italy,2024 +Slovenia ,Match 6, Denmark,2024 +Serbia ,Match 5, England,2024 +Slovenia ,Match 18, Serbia,2024 +Denmark ,Match 17, England,2024 +England ,Match 29, Slovenia,2024 +Denmark ,Match 30, Serbia,2024 +Poland ,Match 7, Netherlands,2024 +Austria ,Match 8, France,2024 +Poland ,Match 19, Austria,2024 +Netherlands ,Match 20, France,2024 +Netherlands ,Match 31, Austria,2024 +France ,Match 32, Poland,2024 +Romania ,Match 10, Ukraine,2024 +Belgium ,Match 9, Slovakia,2024 +Slovakia ,Match 21, Ukraine,2024 +Belgium ,Match 22, Romania,2024 +Slovakia ,Match 33, Romania,2024 +Ukraine ,Match 34, Belgium,2024 +Turkey ,Match 11, Georgia,2024 +Portugal ,Match 12, Czech Republic,2024 +Georgia ,Match 24, Czech Republic,2024 +Turkey ,Match 23, Portugal,2024 +Georgia ,Match 35, Portugal,2024 +Czech Republic ,Match 36, Turkey,2024 +Runner-up Group A,Match 38,Runner-up Group B,2024 +Winner Group A,Match 37,Runner-up Group C,2024 +Winner Group C,Match 40,3rd Group D/E/F,2024 +Winner Group B,Match 39,3rd Group A/D/E/F,2024 +Runner-up Group D,Match 42,Runner-up Group E,2024 +Winner Group F,Match 41,3rd Group A/B/C,2024 +Winner Group E,Match 43,3rd Group A/B/C/D,2024 +Winner Group D,Match 44,Runner-up Group F,2024 +Winner Match 39,Match 45,Winner Match 37,2024 +Winner Match 41,Match 46,Winner Match 42,2024 +Winner Match 40,Match 48,Winner Match 38,2024 +Winner Match 43,Match 47,Winner Match 44,2024 +Winner Match 45,Match 49,Winner Match 46,2024 +Winner Match 47,Match 50,Winner Match 48,2024 +Winner Match 49,Match 51,Winner Match 50,2024 diff --git a/Uefa_euros_historical_data.csv b/Uefa_euros_historical_data.csv new file mode 100644 index 0000000..789bf11 --- /dev/null +++ b/Uefa_euros_historical_data.csv @@ -0,0 +1,317 @@ +home,score,away,year +Czechoslovakia ,0–1, West Germany,1980 +Netherlands ,1–0, Greece,1980 +West Germany ,3–2, Netherlands,1980 +Greece ,1–3, Czechoslovakia,1980 +Netherlands ,1–1, Czechoslovakia,1980 +Greece ,0–0, West Germany,1980 +Belgium ,1–1, England,1980 +Spain ,0–0, Italy,1980 +Belgium ,2–1, Spain,1980 +England ,0–1, Italy,1980 +Spain ,1–2, England,1980 +Italy ,0–0, Belgium,1980 +Czechoslovakia ,1–1, Italy,1980 +Belgium ,1–2, West Germany,1980 +France ,1–0, Denmark,1984 +Belgium ,2–0, Yugoslavia,1984 +France ,5–0, Belgium,1984 +Denmark ,5–0, Yugoslavia,1984 +France ,3–2, Yugoslavia,1984 +Denmark ,3–2, Belgium,1984 +West Germany ,0–0, Portugal,1984 +Romania ,1–1, Spain,1984 +West Germany ,2–1, Romania,1984 +Portugal ,1–1, Spain,1984 +West Germany ,0–1, Spain,1984 +Portugal ,1–0, Romania,1984 +France ,3–2 (a.e.t.), Portugal,1984 +Denmark ,1–1 (a.e.t.), Spain,1984 +France ,2–0, Spain,1984 +West Germany ,1–1, Italy,1988 +Denmark ,2–3, Spain,1988 +West Germany ,2–0, Denmark,1988 +Italy ,1–0, Spain,1988 +West Germany ,2–0, Spain,1988 +Italy ,2–0, Denmark,1988 +England ,0–1, Republic of Ireland,1988 +Netherlands ,0–1, Soviet Union,1988 +England ,1–3, Netherlands,1988 +Republic of Ireland ,1–1, Soviet Union,1988 +England ,1–3, Soviet Union,1988 +Republic of Ireland ,0–1, Netherlands,1988 +West Germany ,1–2, Netherlands,1988 +Soviet Union ,2–0, Italy,1988 +Soviet Union ,0–2, Netherlands,1988 +Sweden ,1–1, France,1992 +Denmark ,0–0, England,1992 +France ,0–0, England,1992 +Sweden ,1–0, Denmark,1992 +Sweden ,2–1, England,1992 +France ,1–2, Denmark,1992 +Netherlands ,1–0, Scotland,1992 +CIS ,1–1, Germany,1992 +Scotland ,0–2, Germany,1992 +Netherlands ,0–0, CIS,1992 +Netherlands ,3–1, Germany,1992 +Scotland ,3–0, CIS,1992 +Sweden ,2–3, Germany,1992 +Netherlands ,2–2 (a.e.t.), Denmark,1992 +Denmark ,2–0, Germany,1992 +England ,1–1,  Switzerland,1996 +Netherlands ,0–0, Scotland,1996 +Switzerland ,0–2, Netherlands,1996 +Scotland ,0–2, England,1996 +Scotland ,1–0,  Switzerland,1996 +Netherlands ,1–4, England,1996 +Spain ,1–1, Bulgaria,1996 +Romania ,0–1, France,1996 +Bulgaria ,1–0, Romania,1996 +France ,1–1, Spain,1996 +France ,3–1, Bulgaria,1996 +Romania ,1–2, Spain,1996 +Germany ,2–0, Czech Republic,1996 +Italy ,2–1, Russia,1996 +Czech Republic ,2–1, Italy,1996 +Russia ,0–3, Germany,1996 +Russia ,3–3, Czech Republic,1996 +Italy ,0–0, Germany,1996 +Denmark ,1–1, Portugal,1996 +Turkey ,0–1, Croatia,1996 +Portugal ,1–0, Turkey,1996 +Croatia ,3–0, Denmark,1996 +Croatia ,0–3, Portugal,1996 +Turkey ,0–3, Denmark,1996 +Spain ,0–0 (a.e.t.), England,1996 +France ,0–0 (a.e.t.), Netherlands,1996 +Germany ,2–1, Croatia,1996 +Czech Republic ,1–0, Portugal,1996 +France ,0–0 (a.e.t.), Czech Republic,1996 +Germany ,1–1 (a.e.t.), England,1996 +Czech Republic ,1–2 (a.e.t./g.g.), Germany,1996 +Germany ,1–1, Romania,2000 +Portugal ,3–2, England,2000 +Romania ,0–1, Portugal,2000 +England ,1–0, Germany,2000 +England ,2–3, Romania,2000 +Portugal ,3–0, Germany,2000 +Belgium ,2–1, Sweden,2000 +Turkey ,1–2, Italy,2000 +Italy ,2–0, Belgium,2000 +Sweden ,0–0, Turkey,2000 +Turkey ,2–0, Belgium,2000 +Italy ,2–1, Sweden,2000 +Spain ,0–1, Norway,2000 +FR Yugoslavia ,3–3, Slovenia,2000 +Slovenia ,1–2, Spain,2000 +Norway ,0–1, FR Yugoslavia,2000 +FR Yugoslavia ,3–4, Spain,2000 +Slovenia ,0–0, Norway,2000 +France ,3–0, Denmark,2000 +Netherlands ,1–0, Czech Republic,2000 +Czech Republic ,1–2, France,2000 +Denmark ,0–3, Netherlands,2000 +Denmark ,0–2, Czech Republic,2000 +France ,2–3, Netherlands,2000 +Portugal ,2–0, Turkey,2000 +Italy ,2–0, Romania,2000 +Netherlands ,6–1, FR Yugoslavia,2000 +Spain ,1–2, France,2000 +France ,2–1 (a.e.t.), Portugal,2000 +Italy ,0–0 (a.e.t.), Netherlands,2000 +France ,2–1 (a.e.t./g.g.), Italy,2000 +Portugal ,1–2, Greece,2004 +Spain ,1–0, Russia,2004 +Greece ,1–1, Spain,2004 +Russia ,0–2, Portugal,2004 +Spain ,0–1, Portugal,2004 +Russia ,2–1, Greece,2004 +Switzerland ,0–0, Croatia,2004 +France ,2–1, England,2004 +England ,3–0,  Switzerland,2004 +Croatia ,2–2, France,2004 +Croatia ,2–4, England,2004 +Switzerland ,1–3, France,2004 +Denmark ,0–0, Italy,2004 +Sweden ,5–0, Bulgaria,2004 +Bulgaria ,0–2, Denmark,2004 +Italy ,1–1, Sweden,2004 +Italy ,2–1, Bulgaria,2004 +Denmark ,2–2, Sweden,2004 +Czech Republic ,2–1, Latvia,2004 +Germany ,1–1, Netherlands,2004 +Latvia ,0–0, Germany,2004 +Netherlands ,2–3, Czech Republic,2004 +Netherlands ,3–0, Latvia,2004 +Germany ,1–2, Czech Republic,2004 +Portugal ,2–2 (a.e.t.), England,2004 +France ,0–1, Greece,2004 +Sweden ,0–0 (a.e.t.), Netherlands,2004 +Czech Republic ,3–0, Denmark,2004 +Portugal ,2–1, Netherlands,2004 +Greece ,1–0 (a.e.t./s.g.), Czech Republic,2004 +Portugal ,0–1, Greece,2004 +Switzerland ,0–1, Czech Republic,2008 +Portugal ,2–0, Turkey,2008 +Czech Republic ,1–3, Portugal,2008 +Switzerland ,1–2, Turkey,2008 +Switzerland ,2–0, Portugal,2008 +Turkey ,3–2, Czech Republic,2008 +Austria ,0–1, Croatia,2008 +Germany ,2–0, Poland,2008 +Croatia ,2–1, Germany,2008 +Austria ,1–1, Poland,2008 +Poland ,0–1, Croatia,2008 +Austria ,0–1, Germany,2008 +Romania ,0–0, France,2008 +Netherlands ,3–0, Italy,2008 +Italy ,1–1, Romania,2008 +Netherlands ,4–1, France,2008 +Netherlands ,2–0, Romania,2008 +France ,0–2, Italy,2008 +Spain ,4–1, Russia,2008 +Greece ,0–2, Sweden,2008 +Sweden ,1–2, Spain,2008 +Greece ,0–1, Russia,2008 +Greece ,1–2, Spain,2008 +Russia ,2–0, Sweden,2008 +Portugal ,2–3, Germany,2008 +Croatia ,1–1 (a.e.t.), Turkey,2008 +Netherlands ,1–3 (a.e.t.), Russia,2008 +Spain ,0–0 (a.e.t.), Italy,2008 +Germany ,3–2, Turkey,2008 +Russia ,0–3, Spain,2008 +Germany ,0–1, Spain,2008 +Poland ,1–1, Greece,2012 +Russia ,4–1, Czech Republic,2012 +Greece ,1–2, Czech Republic,2012 +Poland ,1–1, Russia,2012 +Czech Republic ,1–0, Poland,2012 +Greece ,1–0, Russia,2012 +Netherlands ,0–1, Denmark,2012 +Germany ,1–0, Portugal,2012 +Denmark ,2–3, Portugal,2012 +Netherlands ,1–2, Germany,2012 +Portugal ,2–1, Netherlands,2012 +Denmark ,1–2, Germany,2012 +Spain ,1–1, Italy,2012 +Republic of Ireland ,1–3, Croatia,2012 +Italy ,1–1, Croatia,2012 +Spain ,4–0, Republic of Ireland,2012 +Croatia ,0–1, Spain,2012 +Italy ,2–0, Republic of Ireland,2012 +France ,1–1, England,2012 +Ukraine ,2–1, Sweden,2012 +Ukraine ,0–2, France,2012 +Sweden ,2–3, England,2012 +England ,1–0, Ukraine,2012 +Sweden ,2–0, France,2012 +Czech Republic ,0–1, Portugal,2012 +Germany ,4–2, Greece,2012 +Spain ,2–0, France,2012 +England ,0–0 (a.e.t.), Italy,2012 +Portugal ,0–0 (a.e.t.), Spain,2012 +Germany ,1–2, Italy,2012 +Spain ,4–0, Italy,2012 +France ,2–1, Romania,2016 +Albania ,0–1,  Switzerland,2016 +Romania ,1–1,  Switzerland,2016 +France ,2–0, Albania,2016 +Romania ,0–1, Albania,2016 +Switzerland ,0–0, France,2016 +Wales ,2–1, Slovakia,2016 +England ,1–1, Russia,2016 +Russia ,1–2, Slovakia,2016 +England ,2–1, Wales,2016 +Russia ,0–3, Wales,2016 +Slovakia ,0–0, England,2016 +Poland ,1–0, Northern Ireland,2016 +Germany ,2–0, Ukraine,2016 +Ukraine ,0–2, Northern Ireland,2016 +Germany ,0–0, Poland,2016 +Ukraine ,0–1, Poland,2016 +Northern Ireland ,0–1, Germany,2016 +Turkey ,0–1, Croatia,2016 +Spain ,1–0, Czech Republic,2016 +Czech Republic ,2–2, Croatia,2016 +Spain ,3–0, Turkey,2016 +Czech Republic ,0–2, Turkey,2016 +Croatia ,2–1, Spain,2016 +Republic of Ireland ,1–1, Sweden,2016 +Belgium ,0–2, Italy,2016 +Italy ,1–0, Sweden,2016 +Belgium ,3–0, Republic of Ireland,2016 +Italy ,0–1, Republic of Ireland,2016 +Sweden ,0–1, Belgium,2016 +Austria ,0–2, Hungary,2016 +Portugal ,1–1, Iceland,2016 +Iceland ,1–1, Hungary,2016 +Portugal ,0–0, Austria,2016 +Iceland ,2–1, Austria,2016 +Hungary ,3–3, Portugal,2016 +Switzerland ,1–1 (a.e.t.), Poland,2016 +Wales ,1–0, Northern Ireland,2016 +Croatia ,0–1 (a.e.t.), Portugal,2016 +France ,2–1, Republic of Ireland,2016 +Germany ,3–0, Slovakia,2016 +Hungary ,0–4, Belgium,2016 +Italy ,2–0, Spain,2016 +England ,1–2, Iceland,2016 +Poland ,1–1 (a.e.t.), Portugal,2016 +Wales ,3–1, Belgium,2016 +Germany ,1–1 (a.e.t.), Italy,2016 +France ,5–2, Iceland,2016 +Portugal ,2–0, Wales,2016 +Germany ,0–2, France,2016 +Portugal ,1–0 (a.e.t.), France,2016 +Turkey ,0–3, Italy,2020 +Wales ,1–1,  Switzerland,2020 +Turkey ,0–2, Wales,2020 +Italy ,3–0,  Switzerland,2020 +Switzerland ,3–1, Turkey,2020 +Italy ,1–0, Wales,2020 +Denmark ,0–1, Finland,2020 +Belgium ,3–0, Russia,2020 +Finland ,0–1, Russia,2020 +Denmark ,1–2, Belgium,2020 +Russia ,1–4, Denmark,2020 +Finland ,0–2, Belgium,2020 +Austria ,3–1, North Macedonia,2020 +Netherlands ,3–2, Ukraine,2020 +Ukraine ,2–1, North Macedonia,2020 +Netherlands ,2–0, Austria,2020 +North Macedonia ,0–3, Netherlands,2020 +Ukraine ,0–1, Austria,2020 +England ,1–0, Croatia,2020 +Scotland ,0–2, Czech Republic,2020 +Croatia ,1–1, Czech Republic,2020 +England ,0–0, Scotland,2020 +Croatia ,3–1, Scotland,2020 +Czech Republic ,0–1, England,2020 +Poland ,1–2, Slovakia,2020 +Spain ,0–0, Sweden,2020 +Sweden ,1–0, Slovakia,2020 +Spain ,1–1, Poland,2020 +Slovakia ,0–5, Spain,2020 +Sweden ,3–2, Poland,2020 +Hungary ,0–3, Portugal,2020 +France ,1–0, Germany,2020 +Hungary ,1–1, France,2020 +Portugal ,2–4, Germany,2020 +Portugal ,2–2, France,2020 +Germany ,2–2, Hungary,2020 +Wales ,0–4, Denmark,2020 +Italy ,2–1 (a.e.t.), Austria,2020 +Netherlands ,0–2, Czech Republic,2020 +Belgium ,1–0, Portugal,2020 +Croatia ,3–5 (a.e.t.), Spain,2020 +France ,3–3 (a.e.t.),  Switzerland,2020 +England ,2–0, Germany,2020 +Sweden ,1–2 (a.e.t.), Ukraine,2020 +Switzerland ,1–1 (a.e.t.), Spain,2020 +Belgium ,1–2, Italy,2020 +Czech Republic ,1–2, Denmark,2020 +Ukraine ,0–4, England,2020 +Italy ,1–1 (a.e.t.), Spain,2020 +England ,2–1 (a.e.t.), Denmark,2020 +Italy ,1–1 (a.e.t.), England,2020 diff --git a/clean_Uefa_euros_fixture.csv b/clean_Uefa_euros_fixture.csv new file mode 100644 index 0000000..ea19e56 --- /dev/null +++ b/clean_Uefa_euros_fixture.csv @@ -0,0 +1,52 @@ +home,score,away,year +Germany,Match 1,Scotland,2024 +Hungary,Match 2,Switzerland,2024 +Germany,Match 14,Hungary,2024 +Scotland,Match 13,Switzerland,2024 +Switzerland,Match 25,Germany,2024 +Scotland,Match 26,Hungary,2024 +Spain,Match 3,Croatia,2024 +Italy,Match 4,Albania,2024 +Croatia,Match 15,Albania,2024 +Spain,Match 16,Italy,2024 +Albania,Match 27,Spain,2024 +Croatia,Match 28,Italy,2024 +Slovenia,Match 6,Denmark,2024 +Serbia,Match 5,England,2024 +Slovenia,Match 18,Serbia,2024 +Denmark,Match 17,England,2024 +England,Match 29,Slovenia,2024 +Denmark,Match 30,Serbia,2024 +Poland,Match 7,Netherlands,2024 +Austria,Match 8,France,2024 +Poland,Match 19,Austria,2024 +Netherlands,Match 20,France,2024 +Netherlands,Match 31,Austria,2024 +France,Match 32,Poland,2024 +Romania,Match 10,Ukraine,2024 +Belgium,Match 9,Slovakia,2024 +Slovakia,Match 21,Ukraine,2024 +Belgium,Match 22,Romania,2024 +Slovakia,Match 33,Romania,2024 +Ukraine,Match 34,Belgium,2024 +Turkey,Match 11,Georgia,2024 +Portugal,Match 12,Czech Republic,2024 +Georgia,Match 24,Czech Republic,2024 +Turkey,Match 23,Portugal,2024 +Georgia,Match 35,Portugal,2024 +Czech Republic,Match 36,Turkey,2024 +Runner-up Group A,Match 38,Runner-up Group B,2024 +Winner Group A,Match 37,Runner-up Group C,2024 +Winner Group C,Match 40,3rd Group D/E/F,2024 +Winner Group B,Match 39,3rd Group A/D/E/F,2024 +Runner-up Group D,Match 42,Runner-up Group E,2024 +Winner Group F,Match 41,3rd Group A/B/C,2024 +Winner Group E,Match 43,3rd Group A/B/C/D,2024 +Winner Group D,Match 44,Runner-up Group F,2024 +Winner Match 39,Match 45,Winner Match 37,2024 +Winner Match 41,Match 46,Winner Match 42,2024 +Winner Match 40,Match 48,Winner Match 38,2024 +Winner Match 43,Match 47,Winner Match 44,2024 +Winner Match 45,Match 49,Winner Match 46,2024 +Winner Match 47,Match 50,Winner Match 48,2024 +Winner Match 49,Match 51,Winner Match 50,2024 diff --git a/clean_Uefa_euros_historical_data.csv b/clean_Uefa_euros_historical_data.csv new file mode 100644 index 0000000..4b551d0 --- /dev/null +++ b/clean_Uefa_euros_historical_data.csv @@ -0,0 +1,317 @@ +HomeTeam,AwayTeam,Year,HomeGoals,AwayGoals,TotalGoals +Czechoslovakia,West Germany,1980,0,1,1 +Belgium,West Germany,1980,1,2,3 +Czechoslovakia,Italy,1980,1,1,2 +Italy,Belgium,1980,0,0,0 +England,Italy,1980,0,1,1 +Belgium,Spain,1980,2,1,3 +Spain,Italy,1980,0,0,0 +Spain,England,1980,1,2,3 +Greece,West Germany,1980,0,0,0 +Netherlands,Czechoslovakia,1980,1,1,2 +Greece,Czechoslovakia,1980,1,3,4 +West Germany,Netherlands,1980,3,2,5 +Netherlands,Greece,1980,1,0,1 +Belgium,England,1980,1,1,2 +Portugal,Spain,1984,1,1,2 +France,Spain,1984,2,0,2 +Denmark,Spain,1984,1,1,2 +France,Portugal,1984,3,2,5 +Portugal,Romania,1984,1,0,1 +West Germany,Spain,1984,0,1,1 +West Germany,Romania,1984,2,1,3 +Denmark,Yugoslavia,1984,5,0,5 +West Germany,Portugal,1984,0,0,0 +Denmark,Belgium,1984,3,2,5 +France,Yugoslavia,1984,3,2,5 +France,Belgium,1984,5,0,5 +Belgium,Yugoslavia,1984,2,0,2 +France,Denmark,1984,1,0,1 +Romania,Spain,1984,1,1,2 +Republic of Ireland,Soviet Union,1988,1,1,2 +Soviet Union,Netherlands,1988,0,2,2 +Soviet Union,Italy,1988,2,0,2 +West Germany,Netherlands,1988,1,2,3 +Republic of Ireland,Netherlands,1988,0,1,1 +England,Soviet Union,1988,1,3,4 +England,Netherlands,1988,1,3,4 +Netherlands,Soviet Union,1988,0,1,1 +England,Republic of Ireland,1988,0,1,1 +Italy,Denmark,1988,2,0,2 +West Germany,Spain,1988,2,0,2 +Italy,Spain,1988,1,0,1 +West Germany,Denmark,1988,2,0,2 +Denmark,Spain,1988,2,3,5 +West Germany,Italy,1988,1,1,2 +Denmark,Germany,1992,2,0,2 +Netherlands,Denmark,1992,2,2,4 +Sweden,Germany,1992,2,3,5 +Netherlands,Germany,1992,3,1,4 +Netherlands,CIS,1992,0,0,0 +Scotland,Germany,1992,0,2,2 +CIS,Germany,1992,1,1,2 +Scotland,CIS,1992,3,0,3 +France,Denmark,1992,1,2,3 +Sweden,England,1992,2,1,3 +Sweden,Denmark,1992,1,0,1 +France,England,1992,0,0,0 +Denmark,England,1992,0,0,0 +Sweden,France,1992,1,1,2 +Netherlands,Scotland,1992,1,0,1 +Italy,Germany,1996,0,0,0 +Denmark,Portugal,1996,1,1,2 +Turkey,Croatia,1996,0,1,1 +Portugal,Turkey,1996,1,0,1 +Croatia,Denmark,1996,3,0,3 +Croatia,Portugal,1996,0,3,3 +Czech Republic,Portugal,1996,1,0,1 +France,Netherlands,1996,0,0,0 +Germany,Croatia,1996,2,1,3 +France,Czech Republic,1996,0,0,0 +Germany,England,1996,1,1,2 +Czech Republic,Germany,1996,1,2,3 +Russia,Czech Republic,1996,3,3,6 +Turkey,Denmark,1996,0,3,3 +Russia,Germany,1996,0,3,3 +Spain,England,1996,0,0,0 +Italy,Russia,1996,2,1,3 +Netherlands,Scotland,1996,0,0,0 +Switzerland,Netherlands,1996,0,2,2 +Scotland,England,1996,0,2,2 +Scotland,Switzerland,1996,1,0,1 +Netherlands,England,1996,1,4,5 +Czech Republic,Italy,1996,2,1,3 +England,Switzerland,1996,1,1,2 +Romania,France,1996,0,1,1 +Bulgaria,Romania,1996,1,0,1 +France,Spain,1996,1,1,2 +France,Bulgaria,1996,3,1,4 +Romania,Spain,1996,1,2,3 +Germany,Czech Republic,1996,2,0,2 +Spain,Bulgaria,1996,1,1,2 +Slovenia,Norway,2000,0,0,0 +France,Denmark,2000,3,0,3 +Netherlands,Czech Republic,2000,1,0,1 +Czech Republic,France,2000,1,2,3 +Denmark,Netherlands,2000,0,3,3 +Denmark,Czech Republic,2000,0,2,2 +Netherlands,FR Yugoslavia,2000,6,1,7 +Portugal,Turkey,2000,2,0,2 +Italy,Romania,2000,2,0,2 +Spain,France,2000,1,2,3 +France,Portugal,2000,2,1,3 +Italy,Netherlands,2000,0,0,0 +FR Yugoslavia,Spain,2000,3,4,7 +France,Netherlands,2000,2,3,5 +Norway,FR Yugoslavia,2000,0,1,1 +France,Italy,2000,2,1,3 +FR Yugoslavia,Slovenia,2000,3,3,6 +Germany,Romania,2000,1,1,2 +Portugal,England,2000,3,2,5 +Romania,Portugal,2000,0,1,1 +England,Germany,2000,1,0,1 +England,Romania,2000,2,3,5 +Portugal,Germany,2000,3,0,3 +Slovenia,Spain,2000,1,2,3 +Turkey,Italy,2000,1,2,3 +Italy,Belgium,2000,2,0,2 +Sweden,Turkey,2000,0,0,0 +Turkey,Belgium,2000,2,0,2 +Italy,Sweden,2000,2,1,3 +Spain,Norway,2000,0,1,1 +Belgium,Sweden,2000,2,1,3 +Denmark,Sweden,2004,2,2,4 +Czech Republic,Latvia,2004,2,1,3 +Germany,Netherlands,2004,1,1,2 +Latvia,Germany,2004,0,0,0 +Netherlands,Czech Republic,2004,2,3,5 +Netherlands,Latvia,2004,3,0,3 +Sweden,Netherlands,2004,0,0,0 +Portugal,England,2004,2,2,4 +France,Greece,2004,0,1,1 +Czech Republic,Denmark,2004,3,0,3 +Portugal,Netherlands,2004,2,1,3 +Greece,Czech Republic,2004,1,0,1 +Italy,Bulgaria,2004,2,1,3 +Germany,Czech Republic,2004,1,2,3 +Portugal,Greece,2004,0,1,1 +Italy,Sweden,2004,1,1,2 +Sweden,Bulgaria,2004,5,0,5 +Bulgaria,Denmark,2004,0,2,2 +Portugal,Greece,2004,1,2,3 +Spain,Russia,2004,1,0,1 +Greece,Spain,2004,1,1,2 +Spain,Portugal,2004,0,1,1 +Russia,Greece,2004,2,1,3 +Russia,Portugal,2004,0,2,2 +France,England,2004,2,1,3 +England,Switzerland,2004,3,0,3 +Croatia,France,2004,2,2,4 +Croatia,England,2004,2,4,6 +Switzerland,France,2004,1,3,4 +Denmark,Italy,2004,0,0,0 +Switzerland,Croatia,2004,0,0,0 +Greece,Spain,2008,1,2,3 +Spain,Russia,2008,4,1,5 +Greece,Sweden,2008,0,2,2 +Sweden,Spain,2008,1,2,3 +Greece,Russia,2008,0,1,1 +Russia,Sweden,2008,2,0,2 +France,Italy,2008,0,2,2 +Croatia,Turkey,2008,1,1,2 +Netherlands,Russia,2008,1,3,4 +Spain,Italy,2008,0,0,0 +Germany,Turkey,2008,3,2,5 +Russia,Spain,2008,0,3,3 +Germany,Spain,2008,0,1,1 +Portugal,Germany,2008,2,3,5 +Netherlands,Romania,2008,2,0,2 +Turkey,Czech Republic,2008,3,2,5 +Italy,Romania,2008,1,1,2 +Portugal,Turkey,2008,2,0,2 +Czech Republic,Portugal,2008,1,3,4 +Switzerland,Turkey,2008,1,2,3 +Switzerland,Portugal,2008,2,0,2 +Netherlands,France,2008,4,1,5 +Austria,Croatia,2008,0,1,1 +Switzerland,Czech Republic,2008,0,1,1 +Croatia,Germany,2008,2,1,3 +Austria,Poland,2008,1,1,2 +Poland,Croatia,2008,0,1,1 +Austria,Germany,2008,0,1,1 +Romania,France,2008,0,0,0 +Netherlands,Italy,2008,3,0,3 +Germany,Poland,2008,2,0,2 +Italy,Republic of Ireland,2012,2,0,2 +France,England,2012,1,1,2 +Ukraine,Sweden,2012,2,1,3 +Sweden,England,2012,2,3,5 +England,Ukraine,2012,1,0,1 +Sweden,France,2012,2,0,2 +England,Italy,2012,0,0,0 +Germany,Greece,2012,4,2,6 +Spain,France,2012,2,0,2 +Portugal,Spain,2012,0,0,0 +Germany,Italy,2012,1,2,3 +Spain,Italy,2012,4,0,4 +Croatia,Spain,2012,0,1,1 +Czech Republic,Portugal,2012,0,1,1 +Spain,Republic of Ireland,2012,4,0,4 +Ukraine,France,2012,0,2,2 +Republic of Ireland,Croatia,2012,1,3,4 +Italy,Croatia,2012,1,1,2 +Poland,Greece,2012,1,1,2 +Russia,Czech Republic,2012,4,1,5 +Poland,Russia,2012,1,1,2 +Czech Republic,Poland,2012,1,0,1 +Greece,Russia,2012,1,0,1 +Netherlands,Denmark,2012,0,1,1 +Greece,Czech Republic,2012,1,2,3 +Denmark,Portugal,2012,2,3,5 +Netherlands,Germany,2012,1,2,3 +Portugal,Netherlands,2012,2,1,3 +Denmark,Germany,2012,1,2,3 +Germany,Portugal,2012,1,0,1 +Spain,Italy,2012,1,1,2 +Hungary,Portugal,2016,3,3,6 +Iceland,Austria,2016,2,1,3 +Portugal,Austria,2016,0,0,0 +Iceland,Hungary,2016,1,1,2 +Austria,Hungary,2016,0,2,2 +Sweden,Belgium,2016,0,1,1 +Italy,Republic of Ireland,2016,0,1,1 +Switzerland,Poland,2016,1,1,2 +Portugal,France,2016,1,0,1 +Portugal,Iceland,2016,1,1,2 +Wales,Northern Ireland,2016,1,0,1 +Wales,Belgium,2016,3,1,4 +France,Republic of Ireland,2016,2,1,3 +Germany,Slovakia,2016,3,0,3 +Hungary,Belgium,2016,0,4,4 +Italy,Spain,2016,2,0,2 +England,Iceland,2016,1,2,3 +Poland,Portugal,2016,1,1,2 +Germany,Italy,2016,1,1,2 +France,Iceland,2016,5,2,7 +Portugal,Wales,2016,2,0,2 +Germany,France,2016,0,2,2 +Italy,Sweden,2016,1,0,1 +Croatia,Portugal,2016,0,1,1 +Belgium,Italy,2016,0,2,2 +Belgium,Republic of Ireland,2016,3,0,3 +Croatia,Spain,2016,2,1,3 +France,Romania,2016,2,1,3 +Albania,Switzerland,2016,0,1,1 +Romania,Switzerland,2016,1,1,2 +France,Albania,2016,2,0,2 +Romania,Albania,2016,0,1,1 +Switzerland,France,2016,0,0,0 +Republic of Ireland,Sweden,2016,1,1,2 +England,Russia,2016,1,1,2 +Russia,Slovakia,2016,1,2,3 +England,Wales,2016,2,1,3 +Russia,Wales,2016,0,3,3 +Wales,Slovakia,2016,2,1,3 +Poland,Northern Ireland,2016,1,0,1 +Slovakia,England,2016,0,0,0 +Spain,Turkey,2016,3,0,3 +Czech Republic,Croatia,2016,2,2,4 +Spain,Czech Republic,2016,1,0,1 +Turkey,Croatia,2016,0,1,1 +Czech Republic,Turkey,2016,0,2,2 +Ukraine,Poland,2016,0,1,1 +Germany,Poland,2016,0,0,0 +Ukraine,Northern Ireland,2016,0,2,2 +Germany,Ukraine,2016,2,0,2 +Northern Ireland,Germany,2016,0,1,1 +Spain,Poland,2020,1,1,2 +Slovakia,Spain,2020,0,5,5 +Sweden,Poland,2020,3,2,5 +Hungary,Portugal,2020,0,3,3 +France,Germany,2020,1,0,1 +Hungary,France,2020,1,1,2 +Portugal,Germany,2020,2,4,6 +Portugal,France,2020,2,2,4 +Germany,Hungary,2020,2,2,4 +Wales,Denmark,2020,0,4,4 +Italy,Spain,2020,1,1,2 +Netherlands,Czech Republic,2020,0,2,2 +Belgium,Portugal,2020,1,0,1 +Croatia,Spain,2020,3,5,8 +France,Switzerland,2020,3,3,6 +England,Germany,2020,2,0,2 +Sweden,Ukraine,2020,1,2,3 +Switzerland,Spain,2020,1,1,2 +Belgium,Italy,2020,1,2,3 +Czech Republic,Denmark,2020,1,2,3 +Ukraine,England,2020,0,4,4 +Sweden,Slovakia,2020,1,0,1 +Italy,Austria,2020,2,1,3 +Spain,Sweden,2020,0,0,0 +Austria,North Macedonia,2020,3,1,4 +Czech Republic,England,2020,0,1,1 +England,Denmark,2020,2,1,3 +Turkey,Italy,2020,0,3,3 +Wales,Switzerland,2020,1,1,2 +Turkey,Wales,2020,0,2,2 +Italy,Switzerland,2020,3,0,3 +Switzerland,Turkey,2020,3,1,4 +Italy,Wales,2020,1,0,1 +Denmark,Finland,2020,0,1,1 +Belgium,Russia,2020,3,0,3 +Finland,Russia,2020,0,1,1 +Denmark,Belgium,2020,1,2,3 +Russia,Denmark,2020,1,4,5 +Finland,Belgium,2020,0,2,2 +Netherlands,Ukraine,2020,3,2,5 +Ukraine,North Macedonia,2020,2,1,3 +Netherlands,Austria,2020,2,0,2 +North Macedonia,Netherlands,2020,0,3,3 +Ukraine,Austria,2020,0,1,1 +England,Croatia,2020,1,0,1 +Scotland,Czech Republic,2020,0,2,2 +Croatia,Czech Republic,2020,1,1,2 +England,Scotland,2020,0,0,0 +Croatia,Scotland,2020,3,1,4 +Poland,Slovakia,2020,1,2,3 +Italy,England,2020,1,1,2 diff --git a/data_cleaning.ipynb b/data_cleaning.ipynb new file mode 100644 index 0000000..fa5b3c0 --- /dev/null +++ b/data_cleaning.ipynb @@ -0,0 +1,1247 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 54, + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd" + ] + }, + { + "cell_type": "code", + "execution_count": 55, + "metadata": {}, + "outputs": [], + "source": [ + "df_historical_data = pd.read_csv('Uefa_euros_historical_data.csv')\n", + "df_fixture = pd.read_csv('Uefa_euros_fixture.csv')\n" + ] + }, + { + "cell_type": "code", + "execution_count": 56, + "metadata": {}, + "outputs": [], + "source": [ + "df_fixture['home'] = df_fixture['home'].str.strip()\n", + "df_fixture['away'] = df_fixture['away'].str.strip()" + ] + }, + { + "cell_type": "code", + "execution_count": 57, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
homescoreawayyear
0Czechoslovakia0–1West Germany1980
13Belgium1–2West Germany1980
12Czechoslovakia1–1Italy1980
11Italy0–0Belgium1980
9England0–1Italy1980
...............
285Croatia1–1Czech Republic2020
286England0–0Scotland2020
287Croatia3–1Scotland2020
289Poland1–2Slovakia2020
315Italy1–1 (a.e.t.)England2020
\n", + "

316 rows × 4 columns

\n", + "
" + ], + "text/plain": [ + " home score away year\n", + "0 Czechoslovakia  0–1  West Germany 1980\n", + "13 Belgium  1–2  West Germany 1980\n", + "12 Czechoslovakia  1–1  Italy 1980\n", + "11 Italy  0–0  Belgium 1980\n", + "9 England  0–1  Italy 1980\n", + ".. ... ... ... ...\n", + "285 Croatia  1–1  Czech Republic 2020\n", + "286 England  0–0  Scotland 2020\n", + "287 Croatia  3–1  Scotland 2020\n", + "289 Poland  1–2  Slovakia 2020\n", + "315 Italy  1–1 (a.e.t.)  England 2020\n", + "\n", + "[316 rows x 4 columns]" + ] + }, + "execution_count": 57, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_historical_data.sort_values('year', inplace=True)\n", + "df_historical_data" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "metadata": {}, + "outputs": [], + "source": [ + "df_historical_data['home'] = df_historical_data['home'].str.strip()\n", + "df_historical_data['away'] = df_historical_data['away'].str.strip()\n", + "df_historical_data['score'] = df_historical_data['score'].str.strip()" + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "metadata": {}, + "outputs": [], + "source": [ + "df_historical_data['score'] = df_historical_data['score'].str.replace('[(a.e.t.)]', \"\", regex=True)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 61, + "metadata": {}, + "outputs": [], + "source": [ + "df_historical_data['score'] = df_historical_data['score'].str.replace('(/gg)', \"\", regex=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 63, + "metadata": {}, + "outputs": [], + "source": [ + "df_historical_data['score'] = df_historical_data['score'].str.replace('(/sg)', \"\", regex=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 64, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
homescoreawayyear
0Czechoslovakia0–1West Germany1980
13Belgium1–2West Germany1980
12Czechoslovakia1–1Italy1980
11Italy0–0Belgium1980
9England0–1Italy1980
...............
285Croatia1–1Czech Republic2020
286England0–0Scotland2020
287Croatia3–1Scotland2020
289Poland1–2Slovakia2020
315Italy1–1England2020
\n", + "

316 rows × 4 columns

\n", + "
" + ], + "text/plain": [ + " home score away year\n", + "0 Czechoslovakia 0–1 West Germany 1980\n", + "13 Belgium 1–2 West Germany 1980\n", + "12 Czechoslovakia 1–1 Italy 1980\n", + "11 Italy 0–0 Belgium 1980\n", + "9 England 0–1 Italy 1980\n", + ".. ... ... ... ...\n", + "285 Croatia 1–1 Czech Republic 2020\n", + "286 England 0–0 Scotland 2020\n", + "287 Croatia 3–1 Scotland 2020\n", + "289 Poland 1–2 Slovakia 2020\n", + "315 Italy 1–1 England 2020\n", + "\n", + "[316 rows x 4 columns]" + ] + }, + "execution_count": 64, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_historical_data" + ] + }, + { + "cell_type": "code", + "execution_count": 92, + "metadata": {}, + "outputs": [], + "source": [ + "df = df_historical_data['score'].str.split('', expand=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 97, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "RangeIndex(start=0, stop=6, step=1)" + ] + }, + "execution_count": 97, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df.columns" + ] + }, + { + "cell_type": "code", + "execution_count": 98, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
13
001
1312
1211
1100
901
.........
28511
28600
28731
28912
31511
\n", + "

316 rows × 2 columns

\n", + "
" + ], + "text/plain": [ + " 1 3\n", + "0 0 1\n", + "13 1 2\n", + "12 1 1\n", + "11 0 0\n", + "9 0 1\n", + ".. .. ..\n", + "285 1 1\n", + "286 0 0\n", + "287 3 1\n", + "289 1 2\n", + "315 1 1\n", + "\n", + "[316 rows x 2 columns]" + ] + }, + "execution_count": 98, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "columns_to_keep = [1, 3]\n", + "df = df[columns_to_keep]\n", + "df" + ] + }, + { + "cell_type": "code", + "execution_count": 100, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
homescoreawayyearHomeGoalsAwayGoals
0Czechoslovakia0–1West Germany198001
13Belgium1–2West Germany198012
12Czechoslovakia1–1Italy198011
11Italy0–0Belgium198000
9England0–1Italy198001
.....................
285Croatia1–1Czech Republic202011
286England0–0Scotland202000
287Croatia3–1Scotland202031
289Poland1–2Slovakia202012
315Italy1–1England202011
\n", + "

316 rows × 6 columns

\n", + "
" + ], + "text/plain": [ + " home score away year HomeGoals AwayGoals\n", + "0 Czechoslovakia 0–1 West Germany 1980 0 1\n", + "13 Belgium 1–2 West Germany 1980 1 2\n", + "12 Czechoslovakia 1–1 Italy 1980 1 1\n", + "11 Italy 0–0 Belgium 1980 0 0\n", + "9 England 0–1 Italy 1980 0 1\n", + ".. ... ... ... ... ... ...\n", + "285 Croatia 1–1 Czech Republic 2020 1 1\n", + "286 England 0–0 Scotland 2020 0 0\n", + "287 Croatia 3–1 Scotland 2020 3 1\n", + "289 Poland 1–2 Slovakia 2020 1 2\n", + "315 Italy 1–1 England 2020 1 1\n", + "\n", + "[316 rows x 6 columns]" + ] + }, + "execution_count": 100, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_historical_data[['HomeGoals', 'AwayGoals']] = df\n", + "df_historical_data" + ] + }, + { + "cell_type": "code", + "execution_count": 101, + "metadata": {}, + "outputs": [], + "source": [ + "df_historical_data.drop('score', axis=1, inplace=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 102, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
homeawayyearHomeGoalsAwayGoals
0CzechoslovakiaWest Germany198001
13BelgiumWest Germany198012
12CzechoslovakiaItaly198011
11ItalyBelgium198000
9EnglandItaly198001
..................
285CroatiaCzech Republic202011
286EnglandScotland202000
287CroatiaScotland202031
289PolandSlovakia202012
315ItalyEngland202011
\n", + "

316 rows × 5 columns

\n", + "
" + ], + "text/plain": [ + " home away year HomeGoals AwayGoals\n", + "0 Czechoslovakia West Germany 1980 0 1\n", + "13 Belgium West Germany 1980 1 2\n", + "12 Czechoslovakia Italy 1980 1 1\n", + "11 Italy Belgium 1980 0 0\n", + "9 England Italy 1980 0 1\n", + ".. ... ... ... ... ...\n", + "285 Croatia Czech Republic 2020 1 1\n", + "286 England Scotland 2020 0 0\n", + "287 Croatia Scotland 2020 3 1\n", + "289 Poland Slovakia 2020 1 2\n", + "315 Italy England 2020 1 1\n", + "\n", + "[316 rows x 5 columns]" + ] + }, + "execution_count": 102, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_historical_data" + ] + }, + { + "cell_type": "code", + "execution_count": 103, + "metadata": {}, + "outputs": [], + "source": [ + "df_historical_data.rename(columns={'home': 'HomeTeam', 'away': 'AwayTeam',\n", + " 'year': 'Year'}, inplace=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 104, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
HomeTeamAwayTeamYearHomeGoalsAwayGoals
0CzechoslovakiaWest Germany198001
13BelgiumWest Germany198012
12CzechoslovakiaItaly198011
11ItalyBelgium198000
9EnglandItaly198001
..................
285CroatiaCzech Republic202011
286EnglandScotland202000
287CroatiaScotland202031
289PolandSlovakia202012
315ItalyEngland202011
\n", + "

316 rows × 5 columns

\n", + "
" + ], + "text/plain": [ + " HomeTeam AwayTeam Year HomeGoals AwayGoals\n", + "0 Czechoslovakia West Germany 1980 0 1\n", + "13 Belgium West Germany 1980 1 2\n", + "12 Czechoslovakia Italy 1980 1 1\n", + "11 Italy Belgium 1980 0 0\n", + "9 England Italy 1980 0 1\n", + ".. ... ... ... ... ...\n", + "285 Croatia Czech Republic 2020 1 1\n", + "286 England Scotland 2020 0 0\n", + "287 Croatia Scotland 2020 3 1\n", + "289 Poland Slovakia 2020 1 2\n", + "315 Italy England 2020 1 1\n", + "\n", + "[316 rows x 5 columns]" + ] + }, + "execution_count": 104, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_historical_data" + ] + }, + { + "cell_type": "code", + "execution_count": 110, + "metadata": {}, + "outputs": [], + "source": [ + "df_historical_data = df_historical_data.astype({'HomeGoals':'int64', 'AwayGoals':'int64', 'Year':'int64'})" + ] + }, + { + "cell_type": "code", + "execution_count": 111, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "HomeTeam object\n", + "AwayTeam object\n", + "Year int64\n", + "HomeGoals int64\n", + "AwayGoals int64\n", + "dtype: object" + ] + }, + "execution_count": 111, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_historical_data.dtypes" + ] + }, + { + "cell_type": "code", + "execution_count": 112, + "metadata": {}, + "outputs": [], + "source": [ + "df_historical_data['TotalGoals'] = df_historical_data['HomeGoals'] + df_historical_data['AwayGoals']" + ] + }, + { + "cell_type": "code", + "execution_count": 113, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
HomeTeamAwayTeamYearHomeGoalsAwayGoalsTotalGoals
0CzechoslovakiaWest Germany1980011
13BelgiumWest Germany1980123
12CzechoslovakiaItaly1980112
11ItalyBelgium1980000
9EnglandItaly1980011
.....................
285CroatiaCzech Republic2020112
286EnglandScotland2020000
287CroatiaScotland2020314
289PolandSlovakia2020123
315ItalyEngland2020112
\n", + "

316 rows × 6 columns

\n", + "
" + ], + "text/plain": [ + " HomeTeam AwayTeam Year HomeGoals AwayGoals TotalGoals\n", + "0 Czechoslovakia West Germany 1980 0 1 1\n", + "13 Belgium West Germany 1980 1 2 3\n", + "12 Czechoslovakia Italy 1980 1 1 2\n", + "11 Italy Belgium 1980 0 0 0\n", + "9 England Italy 1980 0 1 1\n", + ".. ... ... ... ... ... ...\n", + "285 Croatia Czech Republic 2020 1 1 2\n", + "286 England Scotland 2020 0 0 0\n", + "287 Croatia Scotland 2020 3 1 4\n", + "289 Poland Slovakia 2020 1 2 3\n", + "315 Italy England 2020 1 1 2\n", + "\n", + "[316 rows x 6 columns]" + ] + }, + "execution_count": 113, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_historical_data" + ] + }, + { + "cell_type": "code", + "execution_count": 114, + "metadata": {}, + "outputs": [], + "source": [ + "df_historical_data.to_csv('clean_Uefa_euros_historical_data.csv', index=False)" + ] + }, + { + "cell_type": "code", + "execution_count": 115, + "metadata": {}, + "outputs": [], + "source": [ + "df_fixture.to_csv('clean_Uefa_euros_fixture.csv', index=False)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "euros_env", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/dict_table b/dict_table new file mode 100644 index 0000000000000000000000000000000000000000..149650fb8658e0a866e1d3939ea5b33c0cd2b5e3 GIT binary patch literal 4457 zcmeH}&rjPh6vxvx&<^$sP3)J%#9;?^>8?9WnxH^|u&$yYwgZct*2GaACv)sE(2%yn z_#yd*_xEnkPMOL!2I>W&HC1BQwcY3UKHr!3#r^(%!m-!Bo>ApGPh>hhtJOq`SO;a* zcEWLWo1++Obz>e0v}pS$`q@`)R=9o~a;={9Pmh?uoFST3W5iI1d8XCPIhwS)uk-Kv zM63I~6+VrEtomz-R(E{K(x}~~*bmGaGkKE9INi;Si6s>g;vDV5u0F@@gk^%uwlEV% z>_n}~V7#4jqCMxEt`!1(sMqw2SAdUupvi<9>4@DFn?=Rwg+4yYe=n)ROWkNRR(`-` zAD$z0a9o=%< z)~Ls-_~wi$pMNvul`&-t+&*5%9Gts5J+t&ot4gb#2nqp%gD*)IA`ZS8Z|y{44|6+? zVIg@6b`&qNq+;DObv);s9=LbD|FJPK1-BKwv3|E5Y7>HoXOZvVPdKXvC1ZJrDOP@LFFq4^U~b z4nw7;$g~Nta+%R-Lmn8)R@9@vS;!F!jfrcf?K6w`4M0{PE&y2NW+F+o=b8?NPQmVp z&Bh>k5DsJmbBxo>;Kx`Xd#)`Y9|-}P-`8r?-=-+E-3N%$WGC}GG6h{AfqjYsOf!9y z$>22c%xU80iG`HO*!e=4x}+W}!(2E&FM#T{(@F7EL~41Dz_*V-_Rc1yQvy5A4ta3y0Z#AQqq4Ll@mGIO!7iw zynzMDs|$Enm1iXsVFt=kC=eOcJ;N+H5SZ7G$%QLtvOI@r7)hv=Y`#QYn;h2?D3EP$ zqs!r)K16aLARXuWA-QVBtmA}-2E$4-;X;OpYIVD|hudU&4W}}IVtAM< M2P5\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PosTeamvtePldWDLGFGAGDPtsQualification
01Turkey00000000Advance to knockout stage
12Georgia00000000Advance to knockout stage
23Portugal00000000Possible knockout stage based on ranking
34Czech Republic00000000NaN
\n", + "" + ], + "text/plain": [ + " Pos Teamvte Pld W D L GF GA GD Pts \\\n", + "0 1 Turkey 0 0 0 0 0 0 0 0 \n", + "1 2 Georgia 0 0 0 0 0 0 0 0 \n", + "2 3 Portugal 0 0 0 0 0 0 0 0 \n", + "3 4 Czech Republic 0 0 0 0 0 0 0 0 \n", + "\n", + " Qualification \n", + "0 Advance to knockout stage \n", + "1 Advance to knockout stage \n", + "2 Possible knockout stage based on ranking \n", + "3 NaN " + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\n", + "all_tables[18]\n", + "all_tables[53]" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "alphabet" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [], + "source": [ + "all_tables = pd.read_html('https://en.wikipedia.org/wiki/UEFA_Euro_2024')\n", + "\n", + "dict_table = {}\n", + "for letter, i in zip(alphabet, range(18, 60, 7)):\n", + " df = all_tables[i]\n", + " df.rename(columns= {df.columns[1]: 'Team'}, inplace=True)\n", + " df.pop('Qualification')\n", + " dict_table[f'Group {letter}'] = df\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
PosTeamPldWDLGFGAGDPts
01Slovenia00000000
12Denmark00000000
23Serbia00000000
34England00000000
\n", + "
" + ], + "text/plain": [ + " Pos Team Pld W D L GF GA GD Pts\n", + "0 1 Slovenia 0 0 0 0 0 0 0 0\n", + "1 2 Denmark 0 0 0 0 0 0 0 0\n", + "2 3 Serbia 0 0 0 0 0 0 0 0\n", + "3 4 England 0 0 0 0 0 0 0 0" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dict_table[\"Group C\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [], + "source": [ + "with open('dict_table', 'wb') as output:\n", + " pickle.dump(dict_table, output)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "euros_env", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/predict_euros.ipynb b/predict_euros.ipynb new file mode 100644 index 0000000..6f9d7ee --- /dev/null +++ b/predict_euros.ipynb @@ -0,0 +1,2268 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd\n", + "import pickle\n", + "from scipy.stats import poisson" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "dict_table = pickle.load(open('dict_table', 'rb'))\n", + "df_historical_data = pd.read_csv('clean_Uefa_euros_historical_data.csv')\n", + "df_fixture = pd.read_csv('clean_Uefa_euros_fixture.csv')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Calculate Team Strength" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
HomeTeamAwayTeamYearHomeGoalsAwayGoalsTotalGoals
0CzechoslovakiaWest Germany1980011
1BelgiumWest Germany1980123
2CzechoslovakiaItaly1980112
3ItalyBelgium1980000
4EnglandItaly1980011
\n", + "
" + ], + "text/plain": [ + " HomeTeam AwayTeam Year HomeGoals AwayGoals TotalGoals\n", + "0 Czechoslovakia West Germany 1980 0 1 1\n", + "1 Belgium West Germany 1980 1 2 3\n", + "2 Czechoslovakia Italy 1980 1 1 2\n", + "3 Italy Belgium 1980 0 0 0\n", + "4 England Italy 1980 0 1 1" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_historical_data.head(5)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "df_home = df_historical_data[['HomeTeam', 'HomeGoals', 'AwayGoals']]\n", + "df_away = df_historical_data[['AwayTeam', 'HomeGoals', 'AwayGoals']]" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "df_home = df_home.rename(columns={'HomeTeam': 'Team', 'HomeGoals': 'GoalsScored', 'AwayGoals': 'GoalsConceded'})\n", + "df_away = df_away.rename(columns={'AwayTeam': 'Team', 'HomeGoals': 'GoalsConceded', 'AwayGoals': 'GoalsScored'})" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
GoalsScoredGoalsConceded
Team
Albania0.3333331.000000
Austria0.7000001.200000
Belgium1.4000001.250000
Bulgaria0.6666672.166667
CIS0.3333331.333333
Croatia1.3636361.272727
Czech Republic1.2413791.275862
Czechoslovakia1.2500001.000000
Denmark1.3225811.419355
England1.3611111.000000
FR Yugoslavia2.0000003.250000
Finland0.3333331.000000
France1.5853661.048780
Germany1.3947371.105263
Greece0.8750001.250000
Hungary1.2857142.000000
Iceland1.6000001.800000
Italy1.1666670.714286
Latvia0.3333331.666667
Netherlands1.6486490.972973
North Macedonia0.6666672.666667
Northern Ireland0.5000000.750000
Norway0.3333330.333333
Poland0.7857141.071429
Portugal1.4358970.974359
Republic of Ireland0.6000001.700000
Romania0.6250001.312500
Russia1.1000001.800000
Scotland0.5555561.111111
Slovakia0.7142861.857143
Slovenia1.3333331.666667
Soviet Union1.4000000.800000
Spain1.4545450.909091
Sweden1.2500001.166667
Switzerland0.8888891.333333
Turkey0.7777781.666667
Ukraine0.7272731.727273
Wales1.3000001.200000
West Germany1.2727270.727273
Yugoslavia0.6666673.333333
\n", + "
" + ], + "text/plain": [ + " GoalsScored GoalsConceded\n", + "Team \n", + "Albania 0.333333 1.000000\n", + "Austria 0.700000 1.200000\n", + "Belgium 1.400000 1.250000\n", + "Bulgaria 0.666667 2.166667\n", + "CIS 0.333333 1.333333\n", + "Croatia 1.363636 1.272727\n", + "Czech Republic 1.241379 1.275862\n", + "Czechoslovakia 1.250000 1.000000\n", + "Denmark 1.322581 1.419355\n", + "England 1.361111 1.000000\n", + "FR Yugoslavia 2.000000 3.250000\n", + "Finland 0.333333 1.000000\n", + "France 1.585366 1.048780\n", + "Germany 1.394737 1.105263\n", + "Greece 0.875000 1.250000\n", + "Hungary 1.285714 2.000000\n", + "Iceland 1.600000 1.800000\n", + "Italy 1.166667 0.714286\n", + "Latvia 0.333333 1.666667\n", + "Netherlands 1.648649 0.972973\n", + "North Macedonia 0.666667 2.666667\n", + "Northern Ireland 0.500000 0.750000\n", + "Norway 0.333333 0.333333\n", + "Poland 0.785714 1.071429\n", + "Portugal 1.435897 0.974359\n", + "Republic of Ireland 0.600000 1.700000\n", + "Romania 0.625000 1.312500\n", + "Russia 1.100000 1.800000\n", + "Scotland 0.555556 1.111111\n", + "Slovakia 0.714286 1.857143\n", + "Slovenia 1.333333 1.666667\n", + "Soviet Union 1.400000 0.800000\n", + "Spain 1.454545 0.909091\n", + "Sweden 1.250000 1.166667\n", + "Switzerland 0.888889 1.333333\n", + "Turkey 0.777778 1.666667\n", + "Ukraine 0.727273 1.727273\n", + "Wales 1.300000 1.200000\n", + "West Germany 1.272727 0.727273\n", + "Yugoslavia 0.666667 3.333333" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_team_strength = pd.concat([df_home, df_away], ignore_index=True).groupby('Team').mean()\n", + "\n", + "df_team_strength" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Function Predict Points" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "def predict_points(home, away):\n", + " if home in df_team_strength.index and away in df_team_strength.index:\n", + " # goals_scored * goals_conceded\n", + " lamb_home = df_team_strength.at[home,'GoalsScored'] * df_team_strength.at[away,'GoalsConceded']\n", + " lamb_away = df_team_strength.at[away,'GoalsScored'] * df_team_strength.at[home,'GoalsConceded']\n", + " prob_home, prob_away, prob_draw = 0, 0, 0\n", + " for x in range(0,11): #number of goals home team\n", + " for y in range(0, 11): #number of goals away team\n", + " p = poisson.pmf(x, lamb_home) * poisson.pmf(y, lamb_away)\n", + " if x == y:\n", + " prob_draw += p\n", + " elif x > y:\n", + " prob_home += p\n", + " else:\n", + " prob_away += p\n", + " \n", + " points_home = 3 * prob_home + prob_draw\n", + " points_away = 3 * prob_away + prob_draw\n", + " return (points_home, points_away)\n", + " else:\n", + " return (0, 0)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Predicting Euros" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Group Stage" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "dict_table['Group A']['Team'] = dict_table['Group A']['Team'].replace({'Germany (H)': 'Germany'})" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [], + "source": [ + "df_fixture_group_36 = df_fixture[:36].copy()\n", + "df_fixture_knockout = df_fixture[36:44].copy()\n", + "df_fixture_quarter = df_fixture[44:48].copy()\n", + "df_fixture_semi = df_fixture[48:50].copy()\n", + "df_fixture_final = df_fixture[50:].copy()" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\Users\\USER\\AppData\\Local\\Temp\\ipykernel_17552\\2645603068.py:7: FutureWarning: Setting an item of incompatible dtype is deprecated and will raise an error in a future version of pandas. Value '[2.0562714]' has dtype incompatible with int64, please explicitly cast to a compatible dtype first.\n", + " dict_table[group].loc[dict_table[group]['Team'] == home, 'Pts'] += points_home\n", + "C:\\Users\\USER\\AppData\\Local\\Temp\\ipykernel_17552\\2645603068.py:7: FutureWarning: Setting an item of incompatible dtype is deprecated and will raise an error in a future version of pandas. Value '[1.77880332]' has dtype incompatible with int64, please explicitly cast to a compatible dtype first.\n", + " dict_table[group].loc[dict_table[group]['Team'] == home, 'Pts'] += points_home\n", + "C:\\Users\\USER\\AppData\\Local\\Temp\\ipykernel_17552\\2645603068.py:7: FutureWarning: Setting an item of incompatible dtype is deprecated and will raise an error in a future version of pandas. Value '[1.22097305]' has dtype incompatible with int64, please explicitly cast to a compatible dtype first.\n", + " dict_table[group].loc[dict_table[group]['Team'] == home, 'Pts'] += points_home\n", + "C:\\Users\\USER\\AppData\\Local\\Temp\\ipykernel_17552\\2645603068.py:7: FutureWarning: Setting an item of incompatible dtype is deprecated and will raise an error in a future version of pandas. Value '[0.70293062]' has dtype incompatible with int64, please explicitly cast to a compatible dtype first.\n", + " dict_table[group].loc[dict_table[group]['Team'] == home, 'Pts'] += points_home\n", + "C:\\Users\\USER\\AppData\\Local\\Temp\\ipykernel_17552\\2645603068.py:7: FutureWarning: Setting an item of incompatible dtype is deprecated and will raise an error in a future version of pandas. Value '[1.44517732]' has dtype incompatible with int64, please explicitly cast to a compatible dtype first.\n", + " dict_table[group].loc[dict_table[group]['Team'] == home, 'Pts'] += points_home\n", + "C:\\Users\\USER\\AppData\\Local\\Temp\\ipykernel_17552\\2645603068.py:7: FutureWarning: Setting an item of incompatible dtype is deprecated and will raise an error in a future version of pandas. Value '[1.78765478]' has dtype incompatible with int64, please explicitly cast to a compatible dtype first.\n", + " dict_table[group].loc[dict_table[group]['Team'] == home, 'Pts'] += points_home\n" + ] + } + ], + "source": [ + "for group in dict_table:\n", + " teams_in_group = dict_table[group]['Team'].values\n", + " df_fixture_group_6 = df_fixture_group_36[df_fixture_group_36['home'].isin(teams_in_group)]\n", + " for index, row in df_fixture_group_6.iterrows():\n", + " home, away = row['home'], row['away']\n", + " points_home, points_away = predict_points(home, away)\n", + " dict_table[group].loc[dict_table[group]['Team'] == home, 'Pts'] += points_home\n", + " dict_table[group].loc[dict_table[group]['Team'] == away, 'Pts'] += points_away\n", + "\n", + " dict_table[group] = dict_table[group].sort_values('Pts', ascending=False).reset_index()\n", + " dict_table[group] = dict_table[group][['Team', 'Pts']]\n", + " dict_table[group] = dict_table[group].round(0)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
TeamPts
0Germany6.0
1Switzerland4.0
2Hungary4.0
3Scotland3.0
\n", + "
" + ], + "text/plain": [ + " Team Pts\n", + "0 Germany 6.0\n", + "1 Switzerland 4.0\n", + "2 Hungary 4.0\n", + "3 Scotland 3.0" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "dict_table['Group A']" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Best Losers " + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [], + "source": [ + "best_losers = []\n", + "for group in dict_table:\n", + " third_place = dict_table[group].loc[2]\n", + " best_losers.append(third_place)\n", + "\n", + "df_best_loser = pd.DataFrame(best_losers)\n", + "df_best_loser = df_best_loser.sort_values('Pts', ascending=False, ignore_index=True)\n", + "df_best_loser = df_best_loser[:4]" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
TeamPts
0Hungary4.0
1Croatia4.0
2Poland3.0
3Ukraine3.0
\n", + "
" + ], + "text/plain": [ + " Team Pts\n", + "0 Hungary 4.0\n", + "1 Croatia 4.0\n", + "2 Poland 3.0\n", + "3 Ukraine 3.0" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_best_loser" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Fixtures based on best loser" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [], + "source": [ + "df_third_place_fixtures = pd.read_csv('third_place_fixtures.csv')" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Group AGroup BGroup CGroup DGroup EGroup F1B vs1C vs1E vs1F vs
0ABCDNaNNaN3A3D3B3C
1ABCNaNENaN3A3E3B3C
2ABCNaNNaNF3A3F3B3C
3ABNaNDENaN3D3E3A3B
4ABNaNDNaNF3D3F3A3B
5ABNaNNaNEF3E3F3B3A
6ANaNCDENaN3E3D3C3A
7ANaNCDNaNF3F3D3C3A
8ANaNCNaNEF3E3F3C3A
9ANaNNaNDEF3E3F3D3A
10NaNBCDENaN3E3D3B3C
11NaNBCDNaNF3F3D3C3B
12NaNBCNaNEF3F3E3C3B
13NaNBNaNDEF3F3E3D3B
14NaNNaNCDEF3F3E3D3C
\n", + "
" + ], + "text/plain": [ + " Group A Group B Group C Group D Group E Group F 1B vs 1C vs 1E vs 1F vs\n", + "0 A B C D NaN NaN 3A 3D 3B 3C\n", + "1 A B C NaN E NaN 3A 3E 3B 3C\n", + "2 A B C NaN NaN F 3A 3F 3B 3C\n", + "3 A B NaN D E NaN 3D 3E 3A 3B\n", + "4 A B NaN D NaN F 3D 3F 3A 3B\n", + "5 A B NaN NaN E F 3E 3F 3B 3A\n", + "6 A NaN C D E NaN 3E 3D 3C 3A\n", + "7 A NaN C D NaN F 3F 3D 3C 3A\n", + "8 A NaN C NaN E F 3E 3F 3C 3A\n", + "9 A NaN NaN D E F 3E 3F 3D 3A\n", + "10 NaN B C D E NaN 3E 3D 3B 3C\n", + "11 NaN B C D NaN F 3F 3D 3C 3B\n", + "12 NaN B C NaN E F 3F 3E 3C 3B\n", + "13 NaN B NaN D E F 3F 3E 3D 3B\n", + "14 NaN NaN C D E F 3F 3E 3D 3C" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_third_place_fixtures" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['Group A', 'Group B', 'Group D', 'Group E']" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Extract the groups that the best losers qualify from\n", + "qualifying_groups = []\n", + "\n", + "# Iterate through each team in the provided list\n", + "for team in df_best_loser['Team']:\n", + " # Check each group in dict_table to find the team\n", + " for group, df in dict_table.items():\n", + " if team in df['Team'].values:\n", + " qualifying_groups.append(group)\n", + " break \n", + "\n", + "\n", + "qualifying_groups" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Group E'" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "qualifying_groups[3]" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['3A', '3D', '3B', '3C']\n" + ] + } + ], + "source": [ + "# Find the row in comb_table that matches the qualifying groups\n", + "for index, row in df_third_place_fixtures.iterrows():\n", + " groups = row[:6].dropna().tolist()\n", + " if all(group in qualifying_groups for groups in groups):\n", + " third_place_combinations = row[6:].dropna().tolist() \n", + " break\n", + "print(third_place_combinations)" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'B'" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "third_place_combinations[2][1]" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'Winner Group B': '3rd Group A',\n", + " 'Winner Group C': '3rd Group D',\n", + " 'Winner Group E': '3rd Group B',\n", + " 'Winner Group F': '3rd Group C'}" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "third_place_fixtures_dict = {'Winner Group B': f'3rd Group {third_place_combinations[0][1]}', \n", + " 'Winner Group C': f'3rd Group {third_place_combinations[1][1]}', \n", + " 'Winner Group E': f'3rd Group {third_place_combinations[2][1]}', \n", + " 'Winner Group F': f'3rd Group {third_place_combinations[3][1]}' }\n", + "\n", + "third_place_fixtures_dict" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
homescoreawayyear
36Runner-up Group AMatch 38Runner-up Group B2024
37Winner Group AMatch 37Runner-up Group C2024
38Winner Group CMatch 403rd Group D/E/F2024
39Winner Group BMatch 393rd Group A/D/E/F2024
40Runner-up Group DMatch 42Runner-up Group E2024
41Winner Group FMatch 413rd Group A/B/C2024
42Winner Group EMatch 433rd Group A/B/C/D2024
43Winner Group DMatch 44Runner-up Group F2024
\n", + "
" + ], + "text/plain": [ + " home score away year\n", + "36 Runner-up Group A Match 38 Runner-up Group B 2024\n", + "37 Winner Group A Match 37 Runner-up Group C 2024\n", + "38 Winner Group C Match 40 3rd Group D/E/F 2024\n", + "39 Winner Group B Match 39 3rd Group A/D/E/F 2024\n", + "40 Runner-up Group D Match 42 Runner-up Group E 2024\n", + "41 Winner Group F Match 41 3rd Group A/B/C 2024\n", + "42 Winner Group E Match 43 3rd Group A/B/C/D 2024\n", + "43 Winner Group D Match 44 Runner-up Group F 2024" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_fixture_knockout" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [], + "source": [ + "def update_fixtures_with_third_place_teams(df_fixture_knockout, third_place_fixtures_dict, dict_table):\n", + " # Iterate through the third place fixture dictionary\n", + " for winner, third_placeholder in third_place_fixtures_dict.items():\n", + " # Extract the group of the third place team from the placeholder\n", + " third_group = third_placeholder.split()[-1]\n", + " full_third_group = f'Group {third_group}'\n", + " \n", + " # Get the actual third place team from the corresponding group\n", + " third_place_team = dict_table[full_third_group].loc[2, 'Team']\n", + " \n", + " # Replace the placeholder with the actual team in the fixtures\n", + " df_fixture_knockout.loc[df_fixture_knockout['home'] == winner, 'away'] = third_place_team\n", + " \n", + " return df_fixture_knockout\n", + "\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
homescoreawayyear
36Runner-up Group AMatch 38Runner-up Group B2024
37Winner Group AMatch 37Runner-up Group C2024
38Winner Group CMatch 40Poland2024
39Winner Group BMatch 39Hungary2024
40Runner-up Group DMatch 42Runner-up Group E2024
41Winner Group FMatch 41Slovenia2024
42Winner Group EMatch 43Croatia2024
43Winner Group DMatch 44Runner-up Group F2024
\n", + "
" + ], + "text/plain": [ + " home score away year\n", + "36 Runner-up Group A Match 38 Runner-up Group B 2024\n", + "37 Winner Group A Match 37 Runner-up Group C 2024\n", + "38 Winner Group C Match 40 Poland 2024\n", + "39 Winner Group B Match 39 Hungary 2024\n", + "40 Runner-up Group D Match 42 Runner-up Group E 2024\n", + "41 Winner Group F Match 41 Slovenia 2024\n", + "42 Winner Group E Match 43 Croatia 2024\n", + "43 Winner Group D Match 44 Runner-up Group F 2024" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "updated_fixtures = update_fixtures_with_third_place_teams(df_fixture_knockout, third_place_fixtures_dict, dict_table)\n", + "updated_fixtures" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Round of 16" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
homescoreawayyear
36Runner-up Group AMatch 38Runner-up Group B2024
37Winner Group AMatch 37Runner-up Group C2024
38Winner Group CMatch 40Poland2024
39Winner Group BMatch 39Hungary2024
40Runner-up Group DMatch 42Runner-up Group E2024
41Winner Group FMatch 41Slovenia2024
42Winner Group EMatch 43Croatia2024
43Winner Group DMatch 44Runner-up Group F2024
\n", + "
" + ], + "text/plain": [ + " home score away year\n", + "36 Runner-up Group A Match 38 Runner-up Group B 2024\n", + "37 Winner Group A Match 37 Runner-up Group C 2024\n", + "38 Winner Group C Match 40 Poland 2024\n", + "39 Winner Group B Match 39 Hungary 2024\n", + "40 Runner-up Group D Match 42 Runner-up Group E 2024\n", + "41 Winner Group F Match 41 Slovenia 2024\n", + "42 Winner Group E Match 43 Croatia 2024\n", + "43 Winner Group D Match 44 Runner-up Group F 2024" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_fixture_knockout" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
homescoreawayyearwinner
36SwitzerlandMatch 38Italy2024?
37GermanyMatch 37Denmark2024?
38EnglandMatch 40Poland2024?
39SpainMatch 39Hungary2024?
40FranceMatch 42Romania2024?
41PortugalMatch 41Slovenia2024?
42BelgiumMatch 43Croatia2024?
43NetherlandsMatch 44Czech Republic2024?
\n", + "
" + ], + "text/plain": [ + " home score away year winner\n", + "36 Switzerland Match 38 Italy 2024 ?\n", + "37 Germany Match 37 Denmark 2024 ?\n", + "38 England Match 40 Poland 2024 ?\n", + "39 Spain Match 39 Hungary 2024 ?\n", + "40 France Match 42 Romania 2024 ?\n", + "41 Portugal Match 41 Slovenia 2024 ?\n", + "42 Belgium Match 43 Croatia 2024 ?\n", + "43 Netherlands Match 44 Czech Republic 2024 ?" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "for group in dict_table:\n", + " group_winner = dict_table[group].loc[0, 'Team']\n", + " runners_up = dict_table[group].loc[1, 'Team']\n", + " df_fixture_knockout.replace({f'Winner {group}':group_winner,\n", + " f'Runner-up {group}':runners_up}, inplace=True)\n", + "\n", + "df_fixture_knockout['winner'] = '?'\n", + "df_fixture_knockout" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [], + "source": [ + "def get_winner(df_fixture_updated):\n", + " for index, row in df_fixture_updated.iterrows():\n", + " home, away = row['home'], row['away']\n", + " points_home, points_away = predict_points(home, away)\n", + " if points_home > points_away:\n", + " winner = home\n", + " else:\n", + " winner = away\n", + " df_fixture_updated.loc[index, 'winner'] = winner\n", + " return df_fixture_updated" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
homescoreawayyearwinner
36SwitzerlandMatch 38Italy2024Italy
37GermanyMatch 37Denmark2024Germany
38EnglandMatch 40Poland2024England
39SpainMatch 39Hungary2024Spain
40FranceMatch 42Romania2024France
41PortugalMatch 41Slovenia2024Portugal
42BelgiumMatch 43Croatia2024Belgium
43NetherlandsMatch 44Czech Republic2024Netherlands
\n", + "
" + ], + "text/plain": [ + " home score away year winner\n", + "36 Switzerland Match 38 Italy 2024 Italy\n", + "37 Germany Match 37 Denmark 2024 Germany\n", + "38 England Match 40 Poland 2024 England\n", + "39 Spain Match 39 Hungary 2024 Spain\n", + "40 France Match 42 Romania 2024 France\n", + "41 Portugal Match 41 Slovenia 2024 Portugal\n", + "42 Belgium Match 43 Croatia 2024 Belgium\n", + "43 Netherlands Match 44 Czech Republic 2024 Netherlands" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "get_winner(df_fixture_knockout)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Quarter Finals " + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [], + "source": [ + "def update_table(df_fixture_round_1, df_fixture_round_2):\n", + " for index, row in df_fixture_round_1.iterrows():\n", + " winner = df_fixture_round_1.loc[index, 'winner']\n", + " match = df_fixture_round_1.loc[index, 'score']\n", + " df_fixture_round_2.replace({f'Winner {match}':winner}, inplace=True)\n", + " df_fixture_round_2['winner'] = '?'\n", + " return df_fixture_round_2" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
homescoreawayyearwinner
44SpainMatch 45Germany2024?
45PortugalMatch 46France2024?
46EnglandMatch 48Italy2024?
47BelgiumMatch 47Netherlands2024?
\n", + "
" + ], + "text/plain": [ + " home score away year winner\n", + "44 Spain Match 45 Germany 2024 ?\n", + "45 Portugal Match 46 France 2024 ?\n", + "46 England Match 48 Italy 2024 ?\n", + "47 Belgium Match 47 Netherlands 2024 ?" + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "update_table(df_fixture_knockout, df_fixture_quarter)" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
homescoreawayyearwinner
44SpainMatch 45Germany2024Spain
45PortugalMatch 46France2024France
46EnglandMatch 48Italy2024Italy
47BelgiumMatch 47Netherlands2024Netherlands
\n", + "
" + ], + "text/plain": [ + " home score away year winner\n", + "44 Spain Match 45 Germany 2024 Spain\n", + "45 Portugal Match 46 France 2024 France\n", + "46 England Match 48 Italy 2024 Italy\n", + "47 Belgium Match 47 Netherlands 2024 Netherlands" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "get_winner(df_fixture_quarter)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Semi Finals" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
homescoreawayyearwinner
48SpainMatch 49France2024?
49NetherlandsMatch 50Italy2024?
\n", + "
" + ], + "text/plain": [ + " home score away year winner\n", + "48 Spain Match 49 France 2024 ?\n", + "49 Netherlands Match 50 Italy 2024 ?" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "update_table(df_fixture_quarter, df_fixture_semi)" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
homescoreawayyearwinner
48SpainMatch 49France2024Spain
49NetherlandsMatch 50Italy2024Netherlands
\n", + "
" + ], + "text/plain": [ + " home score away year winner\n", + "48 Spain Match 49 France 2024 Spain\n", + "49 Netherlands Match 50 Italy 2024 Netherlands" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "get_winner(df_fixture_semi)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Final" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
homescoreawayyearwinner
50SpainMatch 51Netherlands2024?
\n", + "
" + ], + "text/plain": [ + " home score away year winner\n", + "50 Spain Match 51 Netherlands 2024 ?" + ] + }, + "execution_count": 33, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "update_table( df_fixture_semi, df_fixture_final)" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
homescoreawayyearwinner
50SpainMatch 51Netherlands2024Netherlands
\n", + "
" + ], + "text/plain": [ + " home score away year winner\n", + "50 Spain Match 51 Netherlands 2024 Netherlands" + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "get_winner(df_fixture_final)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "euros_env", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/third_place_fixtures.csv b/third_place_fixtures.csv new file mode 100644 index 0000000..956313a --- /dev/null +++ b/third_place_fixtures.csv @@ -0,0 +1,16 @@ +Group A,Group B,Group C,Group D,Group E,Group F,1B vs,1C vs,1E vs,1F vs +A,B,C,D,NaN,NaN,3A,3D,3B,3C +A,B,C,NaN,E,NaN,3A,3E,3B,3C +A,B,C,NaN,NaN,F,3A,3F,3B,3C +A,B,NaN,D,E,NaN,3D,3E,3A,3B +A,B,NaN,D,NaN,F,3D,3F,3A,3B +A,B,NaN,NaN,E,F,3E,3F,3B,3A +A,NaN,C,D,E,NaN,3E,3D,3C,3A +A,NaN,C,D,NaN,F,3F,3D,3C,3A +A,NaN,C,NaN,E,F,3E,3F,3C,3A +A,NaN,NaN,D,E,F,3E,3F,3D,3A +NaN,B,C,D,E,NaN,3E,3D,3B,3C +NaN,B,C,D,NaN,F,3F,3D,3C,3B +NaN,B,C,NaN,E,F,3F,3E,3C,3B +NaN,B,NaN,D,E,F,3F,3E,3D,3B +NaN,NaN,C,D,E,F,3F,3E,3D,3C