Release
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,952 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "5c9991b1",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Generate player votes database, containing votes for Serie A matchday and player.\n",
|
||||
"\n",
|
||||
"Votes data is manually downloaded from https://www.fantacalcio.it/voti-fantacalcio-serie-a\n",
|
||||
"\n",
|
||||
"Serie A calendar is loaded from another file, to add information not containing in votes files: home/away, team opponent."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 11,
|
||||
"id": "b63beb69",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import pandas as pd\n",
|
||||
"import numpy as np"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 12,
|
||||
"id": "a3c39376",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"cal = np.array(pd.read_excel('fantacalcio/seriea_calendar.xlsx', header = None))\n",
|
||||
"\n",
|
||||
"cal_df = pd.DataFrame(columns = ['matchday', 'team1', 'team2'])\n",
|
||||
"\n",
|
||||
"matchday = 0\n",
|
||||
"\n",
|
||||
"for i in range(cal.shape[0]):\n",
|
||||
" if(cal[i, 0][0].isnumeric()):\n",
|
||||
" matchday = matchday + 1\n",
|
||||
" continue\n",
|
||||
" \n",
|
||||
" teams = cal[i, 0].split('-')\n",
|
||||
" \n",
|
||||
" frame = pd.DataFrame([[matchday, teams[0], teams[1]]], columns = cal_df.columns)\n",
|
||||
"\n",
|
||||
" cal_df = pd.concat([cal_df, frame], ignore_index = True)\n",
|
||||
" "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 13,
|
||||
"id": "92d3c6fb",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<div>\n",
|
||||
"<style scoped>\n",
|
||||
" .dataframe tbody tr th:only-of-type {\n",
|
||||
" vertical-align: middle;\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" .dataframe tbody tr th {\n",
|
||||
" vertical-align: top;\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" .dataframe thead th {\n",
|
||||
" text-align: right;\n",
|
||||
" }\n",
|
||||
"</style>\n",
|
||||
"<table border=\"1\" class=\"dataframe\">\n",
|
||||
" <thead>\n",
|
||||
" <tr style=\"text-align: right;\">\n",
|
||||
" <th></th>\n",
|
||||
" <th>matchday</th>\n",
|
||||
" <th>team1</th>\n",
|
||||
" <th>team2</th>\n",
|
||||
" </tr>\n",
|
||||
" </thead>\n",
|
||||
" <tbody>\n",
|
||||
" <tr>\n",
|
||||
" <th>0</th>\n",
|
||||
" <td>1</td>\n",
|
||||
" <td>Fiorentina</td>\n",
|
||||
" <td>Cremonese</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>1</th>\n",
|
||||
" <td>1</td>\n",
|
||||
" <td>Verona</td>\n",
|
||||
" <td>Napoli</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>2</th>\n",
|
||||
" <td>1</td>\n",
|
||||
" <td>Juventus</td>\n",
|
||||
" <td>Sassuolo</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>3</th>\n",
|
||||
" <td>1</td>\n",
|
||||
" <td>Lazio</td>\n",
|
||||
" <td>Bologna</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>4</th>\n",
|
||||
" <td>1</td>\n",
|
||||
" <td>Lecce</td>\n",
|
||||
" <td>Inter</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>...</th>\n",
|
||||
" <td>...</td>\n",
|
||||
" <td>...</td>\n",
|
||||
" <td>...</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>375</th>\n",
|
||||
" <td>38</td>\n",
|
||||
" <td>Milan</td>\n",
|
||||
" <td>Lazio</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>376</th>\n",
|
||||
" <td>38</td>\n",
|
||||
" <td>Sassuolo</td>\n",
|
||||
" <td>Monza</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>377</th>\n",
|
||||
" <td>38</td>\n",
|
||||
" <td>Napoli</td>\n",
|
||||
" <td>Salernitana</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>378</th>\n",
|
||||
" <td>38</td>\n",
|
||||
" <td>Udinese</td>\n",
|
||||
" <td>Sampdoria</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>379</th>\n",
|
||||
" <td>38</td>\n",
|
||||
" <td>Roma</td>\n",
|
||||
" <td>Spezia</td>\n",
|
||||
" </tr>\n",
|
||||
" </tbody>\n",
|
||||
"</table>\n",
|
||||
"<p>380 rows × 3 columns</p>\n",
|
||||
"</div>"
|
||||
],
|
||||
"text/plain": [
|
||||
" matchday team1 team2\n",
|
||||
"0 1 Fiorentina Cremonese\n",
|
||||
"1 1 Verona Napoli\n",
|
||||
"2 1 Juventus Sassuolo\n",
|
||||
"3 1 Lazio Bologna\n",
|
||||
"4 1 Lecce Inter\n",
|
||||
".. ... ... ...\n",
|
||||
"375 38 Milan Lazio\n",
|
||||
"376 38 Sassuolo Monza\n",
|
||||
"377 38 Napoli Salernitana\n",
|
||||
"378 38 Udinese Sampdoria\n",
|
||||
"379 38 Roma Spezia\n",
|
||||
"\n",
|
||||
"[380 rows x 3 columns]"
|
||||
]
|
||||
},
|
||||
"execution_count": 13,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"cal_df"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 14,
|
||||
"id": "0d4a330d",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"df = pd.DataFrame(columns = ['matchday', 'player', 'team', 'oppteam', 'home', 'vote', 'goals', 'assists', 'cards_malus', 'fantavote'])\n",
|
||||
"\n",
|
||||
"LAST_MATCH = 14\n",
|
||||
"\n",
|
||||
"for matchday in range(1, LAST_MATCH + 1):\n",
|
||||
" \n",
|
||||
" votes_file = 'fantacalcio/voti/Voti_Fantacalcio_Stagione_2022_23_Giornata_' + str(matchday) + '.xlsx'\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
" rx = np.array(pd.read_excel(votes_file, header = None))\n",
|
||||
"\n",
|
||||
" read = 0\n",
|
||||
" for i in range(rx.shape[0]):\n",
|
||||
" if(rx[i, 0] == \"Cod.\"):\n",
|
||||
" read = 1\n",
|
||||
" team = rx[i-1, 0];\n",
|
||||
" continue\n",
|
||||
"\n",
|
||||
" if(read):\n",
|
||||
" if(isinstance(rx[i, 0], int)):\n",
|
||||
" if((isinstance(rx[i, 3], float) or isinstance(rx[i, 3], int)) and rx[i, 1] != \"ALL\") :\n",
|
||||
" player = rx[i, 2];\n",
|
||||
" vote = float(rx[i, 3])\n",
|
||||
" goals = rx[i, 4] + rx[i, 8] - rx[i, 5]\n",
|
||||
" assists = rx[i, 12]\n",
|
||||
" cards_malus = rx[i, 10] * 0.5 + rx[i, 11]\n",
|
||||
" \n",
|
||||
" oppteam = ''\n",
|
||||
" home = 0\n",
|
||||
" for j in range(cal_df.shape[0]):\n",
|
||||
" if(cal_df['matchday'][j] == matchday):\n",
|
||||
" if(cal_df['team1'][j] == team):\n",
|
||||
" oppteam = cal_df['team2'][j] \n",
|
||||
" home = 1\n",
|
||||
" elif(cal_df['team2'][j] == team):\n",
|
||||
" oppteam = cal_df['team1'][j] \n",
|
||||
" home = 0\n",
|
||||
"\n",
|
||||
" goals_gen = goals * 3;\n",
|
||||
" if(goals < 0):\n",
|
||||
" goals_gen = goals\n",
|
||||
" \n",
|
||||
" fantavote = vote + goals_gen + assists - cards_malus \n",
|
||||
" \n",
|
||||
" frame = pd.DataFrame([[matchday, player, team, oppteam, home, vote, goals, assists, cards_malus, fantavote]], columns = df.columns)\n",
|
||||
"\n",
|
||||
" df = pd.concat([df, frame], axis = 0, ignore_index = True)\n",
|
||||
" else:\n",
|
||||
" read = 0\n",
|
||||
" continue\n",
|
||||
"\n",
|
||||
" df"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 15,
|
||||
"id": "6ade957d",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<div>\n",
|
||||
"<style scoped>\n",
|
||||
" .dataframe tbody tr th:only-of-type {\n",
|
||||
" vertical-align: middle;\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" .dataframe tbody tr th {\n",
|
||||
" vertical-align: top;\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" .dataframe thead th {\n",
|
||||
" text-align: right;\n",
|
||||
" }\n",
|
||||
"</style>\n",
|
||||
"<table border=\"1\" class=\"dataframe\">\n",
|
||||
" <thead>\n",
|
||||
" <tr style=\"text-align: right;\">\n",
|
||||
" <th></th>\n",
|
||||
" <th>matchday</th>\n",
|
||||
" <th>player</th>\n",
|
||||
" <th>team</th>\n",
|
||||
" <th>oppteam</th>\n",
|
||||
" <th>home</th>\n",
|
||||
" <th>vote</th>\n",
|
||||
" <th>goals</th>\n",
|
||||
" <th>assists</th>\n",
|
||||
" <th>cards_malus</th>\n",
|
||||
" <th>fantavote</th>\n",
|
||||
" </tr>\n",
|
||||
" </thead>\n",
|
||||
" <tbody>\n",
|
||||
" <tr>\n",
|
||||
" <th>0</th>\n",
|
||||
" <td>1</td>\n",
|
||||
" <td>Musso</td>\n",
|
||||
" <td>Atalanta</td>\n",
|
||||
" <td>Sampdoria</td>\n",
|
||||
" <td>0</td>\n",
|
||||
" <td>6.0</td>\n",
|
||||
" <td>0</td>\n",
|
||||
" <td>0</td>\n",
|
||||
" <td>0.5</td>\n",
|
||||
" <td>5.5</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>1</th>\n",
|
||||
" <td>1</td>\n",
|
||||
" <td>Toloi</td>\n",
|
||||
" <td>Atalanta</td>\n",
|
||||
" <td>Sampdoria</td>\n",
|
||||
" <td>0</td>\n",
|
||||
" <td>7.0</td>\n",
|
||||
" <td>1</td>\n",
|
||||
" <td>0</td>\n",
|
||||
" <td>0.0</td>\n",
|
||||
" <td>10.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>2</th>\n",
|
||||
" <td>1</td>\n",
|
||||
" <td>Djimsiti</td>\n",
|
||||
" <td>Atalanta</td>\n",
|
||||
" <td>Sampdoria</td>\n",
|
||||
" <td>0</td>\n",
|
||||
" <td>6.0</td>\n",
|
||||
" <td>0</td>\n",
|
||||
" <td>0</td>\n",
|
||||
" <td>0.0</td>\n",
|
||||
" <td>6.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>3</th>\n",
|
||||
" <td>1</td>\n",
|
||||
" <td>Hateboer</td>\n",
|
||||
" <td>Atalanta</td>\n",
|
||||
" <td>Sampdoria</td>\n",
|
||||
" <td>0</td>\n",
|
||||
" <td>6.0</td>\n",
|
||||
" <td>0</td>\n",
|
||||
" <td>0</td>\n",
|
||||
" <td>0.5</td>\n",
|
||||
" <td>5.5</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>4</th>\n",
|
||||
" <td>1</td>\n",
|
||||
" <td>Okoli</td>\n",
|
||||
" <td>Atalanta</td>\n",
|
||||
" <td>Sampdoria</td>\n",
|
||||
" <td>0</td>\n",
|
||||
" <td>5.5</td>\n",
|
||||
" <td>0</td>\n",
|
||||
" <td>0</td>\n",
|
||||
" <td>0.5</td>\n",
|
||||
" <td>5.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>...</th>\n",
|
||||
" <td>...</td>\n",
|
||||
" <td>...</td>\n",
|
||||
" <td>...</td>\n",
|
||||
" <td>...</td>\n",
|
||||
" <td>...</td>\n",
|
||||
" <td>...</td>\n",
|
||||
" <td>...</td>\n",
|
||||
" <td>...</td>\n",
|
||||
" <td>...</td>\n",
|
||||
" <td>...</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>4010</th>\n",
|
||||
" <td>14</td>\n",
|
||||
" <td>Sulemana I.</td>\n",
|
||||
" <td>Verona</td>\n",
|
||||
" <td>Juventus</td>\n",
|
||||
" <td>1</td>\n",
|
||||
" <td>6.0</td>\n",
|
||||
" <td>0</td>\n",
|
||||
" <td>0</td>\n",
|
||||
" <td>0.0</td>\n",
|
||||
" <td>6.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>4011</th>\n",
|
||||
" <td>14</td>\n",
|
||||
" <td>Lasagna</td>\n",
|
||||
" <td>Verona</td>\n",
|
||||
" <td>Juventus</td>\n",
|
||||
" <td>1</td>\n",
|
||||
" <td>6.0</td>\n",
|
||||
" <td>0</td>\n",
|
||||
" <td>0</td>\n",
|
||||
" <td>0.0</td>\n",
|
||||
" <td>6.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>4012</th>\n",
|
||||
" <td>14</td>\n",
|
||||
" <td>Kallon</td>\n",
|
||||
" <td>Verona</td>\n",
|
||||
" <td>Juventus</td>\n",
|
||||
" <td>1</td>\n",
|
||||
" <td>5.5</td>\n",
|
||||
" <td>0</td>\n",
|
||||
" <td>0</td>\n",
|
||||
" <td>0.0</td>\n",
|
||||
" <td>5.5</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>4013</th>\n",
|
||||
" <td>14</td>\n",
|
||||
" <td>Djuric</td>\n",
|
||||
" <td>Verona</td>\n",
|
||||
" <td>Juventus</td>\n",
|
||||
" <td>1</td>\n",
|
||||
" <td>6.0</td>\n",
|
||||
" <td>0</td>\n",
|
||||
" <td>0</td>\n",
|
||||
" <td>0.5</td>\n",
|
||||
" <td>5.5</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>4014</th>\n",
|
||||
" <td>14</td>\n",
|
||||
" <td>Henry</td>\n",
|
||||
" <td>Verona</td>\n",
|
||||
" <td>Juventus</td>\n",
|
||||
" <td>1</td>\n",
|
||||
" <td>6.5</td>\n",
|
||||
" <td>0</td>\n",
|
||||
" <td>0</td>\n",
|
||||
" <td>0.0</td>\n",
|
||||
" <td>6.5</td>\n",
|
||||
" </tr>\n",
|
||||
" </tbody>\n",
|
||||
"</table>\n",
|
||||
"<p>4015 rows × 10 columns</p>\n",
|
||||
"</div>"
|
||||
],
|
||||
"text/plain": [
|
||||
" matchday player team oppteam home vote goals assists \\\n",
|
||||
"0 1 Musso Atalanta Sampdoria 0 6.0 0 0 \n",
|
||||
"1 1 Toloi Atalanta Sampdoria 0 7.0 1 0 \n",
|
||||
"2 1 Djimsiti Atalanta Sampdoria 0 6.0 0 0 \n",
|
||||
"3 1 Hateboer Atalanta Sampdoria 0 6.0 0 0 \n",
|
||||
"4 1 Okoli Atalanta Sampdoria 0 5.5 0 0 \n",
|
||||
"... ... ... ... ... ... ... ... ... \n",
|
||||
"4010 14 Sulemana I. Verona Juventus 1 6.0 0 0 \n",
|
||||
"4011 14 Lasagna Verona Juventus 1 6.0 0 0 \n",
|
||||
"4012 14 Kallon Verona Juventus 1 5.5 0 0 \n",
|
||||
"4013 14 Djuric Verona Juventus 1 6.0 0 0 \n",
|
||||
"4014 14 Henry Verona Juventus 1 6.5 0 0 \n",
|
||||
"\n",
|
||||
" cards_malus fantavote \n",
|
||||
"0 0.5 5.5 \n",
|
||||
"1 0.0 10.0 \n",
|
||||
"2 0.0 6.0 \n",
|
||||
"3 0.5 5.5 \n",
|
||||
"4 0.5 5.0 \n",
|
||||
"... ... ... \n",
|
||||
"4010 0.0 6.0 \n",
|
||||
"4011 0.0 6.0 \n",
|
||||
"4012 0.0 5.5 \n",
|
||||
"4013 0.5 5.5 \n",
|
||||
"4014 0.0 6.5 \n",
|
||||
"\n",
|
||||
"[4015 rows x 10 columns]"
|
||||
]
|
||||
},
|
||||
"execution_count": 15,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"df"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 16,
|
||||
"id": "230213fe",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"df.to_excel('mid_outputs/players_votes.xlsx')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "ef91ece3",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Elaborate data for past seasons.\n",
|
||||
"\n",
|
||||
"Do not repeat if data is already present."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
"id": "da35bdf9",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<div>\n",
|
||||
"<style scoped>\n",
|
||||
" .dataframe tbody tr th:only-of-type {\n",
|
||||
" vertical-align: middle;\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" .dataframe tbody tr th {\n",
|
||||
" vertical-align: top;\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" .dataframe thead th {\n",
|
||||
" text-align: right;\n",
|
||||
" }\n",
|
||||
"</style>\n",
|
||||
"<table border=\"1\" class=\"dataframe\">\n",
|
||||
" <thead>\n",
|
||||
" <tr style=\"text-align: right;\">\n",
|
||||
" <th></th>\n",
|
||||
" <th>matchday</th>\n",
|
||||
" <th>team1</th>\n",
|
||||
" <th>team2</th>\n",
|
||||
" </tr>\n",
|
||||
" </thead>\n",
|
||||
" <tbody>\n",
|
||||
" <tr>\n",
|
||||
" <th>0</th>\n",
|
||||
" <td>1</td>\n",
|
||||
" <td>Verona</td>\n",
|
||||
" <td>Sassuolo</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>1</th>\n",
|
||||
" <td>1</td>\n",
|
||||
" <td>Inter</td>\n",
|
||||
" <td>Genoa</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>2</th>\n",
|
||||
" <td>1</td>\n",
|
||||
" <td>Empoli</td>\n",
|
||||
" <td>Lazio</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>3</th>\n",
|
||||
" <td>1</td>\n",
|
||||
" <td>Torino</td>\n",
|
||||
" <td>Atalanta</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>4</th>\n",
|
||||
" <td>1</td>\n",
|
||||
" <td>Bologna</td>\n",
|
||||
" <td>Salernitana</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>...</th>\n",
|
||||
" <td>...</td>\n",
|
||||
" <td>...</td>\n",
|
||||
" <td>...</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>375</th>\n",
|
||||
" <td>38</td>\n",
|
||||
" <td>Spezia</td>\n",
|
||||
" <td>Napoli</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>376</th>\n",
|
||||
" <td>38</td>\n",
|
||||
" <td>Sassuolo</td>\n",
|
||||
" <td>Milan</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>377</th>\n",
|
||||
" <td>38</td>\n",
|
||||
" <td>Inter</td>\n",
|
||||
" <td>Sampdoria</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>378</th>\n",
|
||||
" <td>38</td>\n",
|
||||
" <td>Salernitana</td>\n",
|
||||
" <td>Udinese</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>379</th>\n",
|
||||
" <td>38</td>\n",
|
||||
" <td>Venezia</td>\n",
|
||||
" <td>Cagliari</td>\n",
|
||||
" </tr>\n",
|
||||
" </tbody>\n",
|
||||
"</table>\n",
|
||||
"<p>380 rows × 3 columns</p>\n",
|
||||
"</div>"
|
||||
],
|
||||
"text/plain": [
|
||||
" matchday team1 team2\n",
|
||||
"0 1 Verona Sassuolo\n",
|
||||
"1 1 Inter Genoa\n",
|
||||
"2 1 Empoli Lazio\n",
|
||||
"3 1 Torino Atalanta\n",
|
||||
"4 1 Bologna Salernitana\n",
|
||||
".. ... ... ...\n",
|
||||
"375 38 Spezia Napoli\n",
|
||||
"376 38 Sassuolo Milan\n",
|
||||
"377 38 Inter Sampdoria\n",
|
||||
"378 38 Salernitana Udinese\n",
|
||||
"379 38 Venezia Cagliari\n",
|
||||
"\n",
|
||||
"[380 rows x 3 columns]"
|
||||
]
|
||||
},
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"cal_df = pd.read_excel('fantacalcio/season2122/seriea_calendar.xlsx')\n",
|
||||
"\n",
|
||||
"to_drop = list()\n",
|
||||
"\n",
|
||||
"for i in range(cal_df.shape[0]):\n",
|
||||
" if(not isinstance(cal_df['matchday'][i], int)):\n",
|
||||
" to_drop.append(i)\n",
|
||||
" \n",
|
||||
"cal_df = cal_df.drop(to_drop)\n",
|
||||
"\n",
|
||||
"cal_df = cal_df.reset_index(drop = True)\n",
|
||||
"\n",
|
||||
"cal_df"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"id": "0313a0f4",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"df = pd.DataFrame(columns = ['matchday', 'player', 'team', 'oppteam', 'home', 'vote', 'goals', 'assists', 'cards_malus', 'fantavote'])\n",
|
||||
"\n",
|
||||
"LAST_MATCH = 38\n",
|
||||
"\n",
|
||||
"for matchday in range(1, LAST_MATCH + 1):\n",
|
||||
" \n",
|
||||
" votes_file = 'fantacalcio/season2122/voti/Voti_Fantacalcio_Stagione_2021_22_Giornata_' + str(matchday) + '.xlsx'\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
" rx = np.array(pd.read_excel(votes_file, header = None))\n",
|
||||
"\n",
|
||||
" read = 0\n",
|
||||
" for i in range(rx.shape[0]):\n",
|
||||
" if(rx[i, 0] == \"Cod.\"):\n",
|
||||
" read = 1\n",
|
||||
" team = rx[i-1, 0];\n",
|
||||
" continue\n",
|
||||
"\n",
|
||||
" if(read):\n",
|
||||
" if(isinstance(rx[i, 0], int)):\n",
|
||||
" if((isinstance(rx[i, 3], float) or isinstance(rx[i, 3], int)) and rx[i, 1] != \"ALL\") :\n",
|
||||
" player = rx[i, 2];\n",
|
||||
" vote = float(rx[i, 3])\n",
|
||||
" goals = rx[i, 4] + rx[i, 8] - rx[i, 5]\n",
|
||||
" assists = rx[i, 12]\n",
|
||||
" cards_malus = rx[i, 10] * 0.5 + rx[i, 11]\n",
|
||||
" \n",
|
||||
" oppteam = ''\n",
|
||||
" home = 0\n",
|
||||
" for j in range(cal_df.shape[0]):\n",
|
||||
" if(cal_df['matchday'][j] == matchday):\n",
|
||||
" if(cal_df['team1'][j] == team):\n",
|
||||
" oppteam = cal_df['team2'][j] \n",
|
||||
" home = 1\n",
|
||||
" elif(cal_df['team2'][j] == team):\n",
|
||||
" oppteam = cal_df['team1'][j] \n",
|
||||
" home = 0\n",
|
||||
"\n",
|
||||
" goals_gen = goals * 3;\n",
|
||||
" if(goals < 0):\n",
|
||||
" goals_gen = goals\n",
|
||||
" \n",
|
||||
" fantavote = vote + goals_gen + assists - cards_malus \n",
|
||||
" \n",
|
||||
" frame = pd.DataFrame([[matchday, player, team, oppteam, home, vote, goals, assists, cards_malus, fantavote]], columns = df.columns)\n",
|
||||
"\n",
|
||||
" df = pd.concat([df, frame], axis = 0, ignore_index = True)\n",
|
||||
" else:\n",
|
||||
" read = 0\n",
|
||||
" continue\n",
|
||||
"\n",
|
||||
" df"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 9,
|
||||
"id": "82b1cfc8",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"df.to_excel('mid_outputs/season2122/players_votes.xlsx')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 10,
|
||||
"id": "d1fca3ba",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<div>\n",
|
||||
"<style scoped>\n",
|
||||
" .dataframe tbody tr th:only-of-type {\n",
|
||||
" vertical-align: middle;\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" .dataframe tbody tr th {\n",
|
||||
" vertical-align: top;\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" .dataframe thead th {\n",
|
||||
" text-align: right;\n",
|
||||
" }\n",
|
||||
"</style>\n",
|
||||
"<table border=\"1\" class=\"dataframe\">\n",
|
||||
" <thead>\n",
|
||||
" <tr style=\"text-align: right;\">\n",
|
||||
" <th></th>\n",
|
||||
" <th>matchday</th>\n",
|
||||
" <th>team1</th>\n",
|
||||
" <th>team2</th>\n",
|
||||
" </tr>\n",
|
||||
" </thead>\n",
|
||||
" <tbody>\n",
|
||||
" <tr>\n",
|
||||
" <th>0</th>\n",
|
||||
" <td>1</td>\n",
|
||||
" <td>Fiorentina</td>\n",
|
||||
" <td>Torino</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>1</th>\n",
|
||||
" <td>1</td>\n",
|
||||
" <td>Verona</td>\n",
|
||||
" <td>Roma</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>2</th>\n",
|
||||
" <td>1</td>\n",
|
||||
" <td>Parma</td>\n",
|
||||
" <td>Napoli</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>3</th>\n",
|
||||
" <td>1</td>\n",
|
||||
" <td>Genoa</td>\n",
|
||||
" <td>Crotone</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>4</th>\n",
|
||||
" <td>1</td>\n",
|
||||
" <td>Sassuolo</td>\n",
|
||||
" <td>Cagliari</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>...</th>\n",
|
||||
" <td>...</td>\n",
|
||||
" <td>...</td>\n",
|
||||
" <td>...</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>375</th>\n",
|
||||
" <td>38</td>\n",
|
||||
" <td>Sassuolo</td>\n",
|
||||
" <td>Lazio</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>376</th>\n",
|
||||
" <td>38</td>\n",
|
||||
" <td>Atalanta</td>\n",
|
||||
" <td>Milan</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>377</th>\n",
|
||||
" <td>38</td>\n",
|
||||
" <td>Torino</td>\n",
|
||||
" <td>Benevento</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>378</th>\n",
|
||||
" <td>38</td>\n",
|
||||
" <td>Bologna</td>\n",
|
||||
" <td>Juventus</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>379</th>\n",
|
||||
" <td>38</td>\n",
|
||||
" <td>Napoli</td>\n",
|
||||
" <td>Verona</td>\n",
|
||||
" </tr>\n",
|
||||
" </tbody>\n",
|
||||
"</table>\n",
|
||||
"<p>380 rows × 3 columns</p>\n",
|
||||
"</div>"
|
||||
],
|
||||
"text/plain": [
|
||||
" matchday team1 team2\n",
|
||||
"0 1 Fiorentina Torino\n",
|
||||
"1 1 Verona Roma\n",
|
||||
"2 1 Parma Napoli\n",
|
||||
"3 1 Genoa Crotone\n",
|
||||
"4 1 Sassuolo Cagliari\n",
|
||||
".. ... ... ...\n",
|
||||
"375 38 Sassuolo Lazio\n",
|
||||
"376 38 Atalanta Milan\n",
|
||||
"377 38 Torino Benevento\n",
|
||||
"378 38 Bologna Juventus\n",
|
||||
"379 38 Napoli Verona\n",
|
||||
"\n",
|
||||
"[380 rows x 3 columns]"
|
||||
]
|
||||
},
|
||||
"execution_count": 10,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"cal_df = pd.read_excel('fantacalcio/season2021/seriea_calendar.xlsx')\n",
|
||||
"\n",
|
||||
"to_drop = list()\n",
|
||||
"\n",
|
||||
"for i in range(cal_df.shape[0]):\n",
|
||||
" if(not isinstance(cal_df['matchday'][i], int)):\n",
|
||||
" to_drop.append(i)\n",
|
||||
" \n",
|
||||
"cal_df = cal_df.drop(to_drop)\n",
|
||||
"\n",
|
||||
"cal_df = cal_df.reset_index(drop = True)\n",
|
||||
"\n",
|
||||
"cal_df"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 11,
|
||||
"id": "6d5d4101",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"df = pd.DataFrame(columns = ['matchday', 'player', 'team', 'oppteam', 'home', 'vote', 'goals', 'assists', 'cards_malus', 'fantavote'])\n",
|
||||
"\n",
|
||||
"LAST_MATCH = 38\n",
|
||||
"\n",
|
||||
"for matchday in range(1, LAST_MATCH + 1):\n",
|
||||
" \n",
|
||||
" votes_file = 'fantacalcio/season2021/voti/Voti_Fantacalcio_Stagione_2020_21_Giornata_' + str(matchday) + '.xlsx'\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
" rx = np.array(pd.read_excel(votes_file, header = None))\n",
|
||||
"\n",
|
||||
" read = 0\n",
|
||||
" for i in range(rx.shape[0]):\n",
|
||||
" if(rx[i, 0] == \"Cod.\"):\n",
|
||||
" read = 1\n",
|
||||
" team = rx[i-1, 0];\n",
|
||||
" continue\n",
|
||||
"\n",
|
||||
" if(read):\n",
|
||||
" if(isinstance(rx[i, 0], int)):\n",
|
||||
" if((isinstance(rx[i, 3], float) or isinstance(rx[i, 3], int)) and rx[i, 1] != \"ALL\") :\n",
|
||||
" player = rx[i, 2];\n",
|
||||
" vote = float(rx[i, 3])\n",
|
||||
" goals = rx[i, 4] + rx[i, 8] - rx[i, 5]\n",
|
||||
" assists = rx[i, 12]\n",
|
||||
" cards_malus = rx[i, 10] * 0.5 + rx[i, 11]\n",
|
||||
" \n",
|
||||
" oppteam = ''\n",
|
||||
" home = 0\n",
|
||||
" for j in range(cal_df.shape[0]):\n",
|
||||
" if(cal_df['matchday'][j] == matchday):\n",
|
||||
" if(cal_df['team1'][j] == team):\n",
|
||||
" oppteam = cal_df['team2'][j] \n",
|
||||
" home = 1\n",
|
||||
" elif(cal_df['team2'][j] == team):\n",
|
||||
" oppteam = cal_df['team1'][j] \n",
|
||||
" home = 0\n",
|
||||
"\n",
|
||||
" goals_gen = goals * 3;\n",
|
||||
" if(goals < 0):\n",
|
||||
" goals_gen = goals\n",
|
||||
" \n",
|
||||
" fantavote = vote + goals_gen + assists - cards_malus \n",
|
||||
" \n",
|
||||
" frame = pd.DataFrame([[matchday, player, team, oppteam, home, vote, goals, assists, cards_malus, fantavote]], columns = df.columns)\n",
|
||||
"\n",
|
||||
" df = pd.concat([df, frame], axis = 0, ignore_index = True)\n",
|
||||
" else:\n",
|
||||
" read = 0\n",
|
||||
" continue\n",
|
||||
"\n",
|
||||
" df"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 12,
|
||||
"id": "0a4bbffd",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"df.to_excel('mid_outputs/season2021/players_votes.xlsx')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "48a341c2",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"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.9.13"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,826 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "fd8a6cb9",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Scraping for playing probability for the current Serie A matchday.\n",
|
||||
"\n",
|
||||
"Data from http://fantacalcio.it"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"id": "4c7b7d26",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import requests\n",
|
||||
"from bs4 import BeautifulSoup\n",
|
||||
"import pandas as pd\n",
|
||||
"import numpy as np\n",
|
||||
"import re\n",
|
||||
"import sys, getopt\n",
|
||||
"import csv\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"id": "91897dbb",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"res = requests.get('https://www.fantacalcio.it/probabili-formazioni-serie-a')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"id": "7ba89027",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<div>\n",
|
||||
"<style scoped>\n",
|
||||
" .dataframe tbody tr th:only-of-type {\n",
|
||||
" vertical-align: middle;\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" .dataframe tbody tr th {\n",
|
||||
" vertical-align: top;\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" .dataframe thead th {\n",
|
||||
" text-align: right;\n",
|
||||
" }\n",
|
||||
"</style>\n",
|
||||
"<table border=\"1\" class=\"dataframe\">\n",
|
||||
" <thead>\n",
|
||||
" <tr style=\"text-align: right;\">\n",
|
||||
" <th></th>\n",
|
||||
" <th>player</th>\n",
|
||||
" <th>starter</th>\n",
|
||||
" <th>percentage</th>\n",
|
||||
" </tr>\n",
|
||||
" </thead>\n",
|
||||
" <tbody>\n",
|
||||
" <tr>\n",
|
||||
" <th>0</th>\n",
|
||||
" <td>Vicario</td>\n",
|
||||
" <td>1</td>\n",
|
||||
" <td>100.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>1</th>\n",
|
||||
" <td>Ebuehi</td>\n",
|
||||
" <td>1</td>\n",
|
||||
" <td>100.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>2</th>\n",
|
||||
" <td>Ismajli</td>\n",
|
||||
" <td>1</td>\n",
|
||||
" <td>100.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>3</th>\n",
|
||||
" <td>Walukiewicz</td>\n",
|
||||
" <td>1</td>\n",
|
||||
" <td>100.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>4</th>\n",
|
||||
" <td>Parisi</td>\n",
|
||||
" <td>1</td>\n",
|
||||
" <td>100.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>...</th>\n",
|
||||
" <td>...</td>\n",
|
||||
" <td>...</td>\n",
|
||||
" <td>...</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>444</th>\n",
|
||||
" <td>Basic</td>\n",
|
||||
" <td>0</td>\n",
|
||||
" <td>55.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>445</th>\n",
|
||||
" <td>Bertini</td>\n",
|
||||
" <td>0</td>\n",
|
||||
" <td>10.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>446</th>\n",
|
||||
" <td>Marcos Antonio</td>\n",
|
||||
" <td>0</td>\n",
|
||||
" <td>50.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>447</th>\n",
|
||||
" <td>Romero L.</td>\n",
|
||||
" <td>0</td>\n",
|
||||
" <td>50.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>448</th>\n",
|
||||
" <td>Cancellieri</td>\n",
|
||||
" <td>0</td>\n",
|
||||
" <td>55.0</td>\n",
|
||||
" </tr>\n",
|
||||
" </tbody>\n",
|
||||
"</table>\n",
|
||||
"<p>449 rows × 3 columns</p>\n",
|
||||
"</div>"
|
||||
],
|
||||
"text/plain": [
|
||||
" player starter percentage\n",
|
||||
"0 Vicario 1 100.0\n",
|
||||
"1 Ebuehi 1 100.0\n",
|
||||
"2 Ismajli 1 100.0\n",
|
||||
"3 Walukiewicz 1 100.0\n",
|
||||
"4 Parisi 1 100.0\n",
|
||||
".. ... ... ...\n",
|
||||
"444 Basic 0 55.0\n",
|
||||
"445 Bertini 0 10.0\n",
|
||||
"446 Marcos Antonio 0 50.0\n",
|
||||
"447 Romero L. 0 50.0\n",
|
||||
"448 Cancellieri 0 55.0\n",
|
||||
"\n",
|
||||
"[449 rows x 3 columns]"
|
||||
]
|
||||
},
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"soup = BeautifulSoup(res.text)\n",
|
||||
"\n",
|
||||
"groups = soup.findAll('ul', attrs = {'class' : 'player-list'})\n",
|
||||
"\n",
|
||||
"probables = pd.DataFrame(columns = ['player', 'starter', 'percentage'])\n",
|
||||
"\n",
|
||||
"for i in range (len(groups)):\n",
|
||||
" players = groups[i].findAll('a', attrs = {'class' : 'player-name'})\n",
|
||||
" bars = groups[i].findAll('div', attrs = {'class' : 'progress-bar'})\n",
|
||||
" \n",
|
||||
" starter_string = groups[i]['class'][1]\n",
|
||||
" if(starter_string == 'starters'):\n",
|
||||
" starter = 1\n",
|
||||
" else:\n",
|
||||
" starter = 0\n",
|
||||
" \n",
|
||||
" for j in range(len(players)):\n",
|
||||
" player = players[j].contents[0].replace('\\n \\n ', '')\n",
|
||||
" perc = float(bars[j]['aria-valuenow'])\n",
|
||||
" \n",
|
||||
" row_df = pd.DataFrame([[player, starter, perc]], columns = probables.columns)\n",
|
||||
" \n",
|
||||
" probables = pd.concat([probables, row_df], ignore_index = True)\n",
|
||||
" \n",
|
||||
"probables "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"id": "29e5b389",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"probables = probables.set_index('player')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"id": "d711726e",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<div>\n",
|
||||
"<style scoped>\n",
|
||||
" .dataframe tbody tr th:only-of-type {\n",
|
||||
" vertical-align: middle;\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" .dataframe tbody tr th {\n",
|
||||
" vertical-align: top;\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" .dataframe thead th {\n",
|
||||
" text-align: right;\n",
|
||||
" }\n",
|
||||
"</style>\n",
|
||||
"<table border=\"1\" class=\"dataframe\">\n",
|
||||
" <thead>\n",
|
||||
" <tr style=\"text-align: right;\">\n",
|
||||
" <th></th>\n",
|
||||
" <th>player1</th>\n",
|
||||
" <th>player2</th>\n",
|
||||
" <th>percentage</th>\n",
|
||||
" </tr>\n",
|
||||
" </thead>\n",
|
||||
" <tbody>\n",
|
||||
" <tr>\n",
|
||||
" <th>0</th>\n",
|
||||
" <td>Lozano</td>\n",
|
||||
" <td>Politano</td>\n",
|
||||
" <td>60.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>1</th>\n",
|
||||
" <td>Zambo Anguissa</td>\n",
|
||||
" <td>Ndombele'</td>\n",
|
||||
" <td>60.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>2</th>\n",
|
||||
" <td>Mario Rui</td>\n",
|
||||
" <td>Olivera</td>\n",
|
||||
" <td>55.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>3</th>\n",
|
||||
" <td>Elmas</td>\n",
|
||||
" <td>Raspadori</td>\n",
|
||||
" <td>55.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>4</th>\n",
|
||||
" <td>Beto</td>\n",
|
||||
" <td>Success</td>\n",
|
||||
" <td>60.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>5</th>\n",
|
||||
" <td>Lovric</td>\n",
|
||||
" <td>Samardzic</td>\n",
|
||||
" <td>55.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>6</th>\n",
|
||||
" <td>Ehizibue</td>\n",
|
||||
" <td>Nuytinck</td>\n",
|
||||
" <td>60.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>7</th>\n",
|
||||
" <td>Rincon</td>\n",
|
||||
" <td>Vieira</td>\n",
|
||||
" <td>60.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>8</th>\n",
|
||||
" <td>Augello</td>\n",
|
||||
" <td>Murru</td>\n",
|
||||
" <td>55.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>9</th>\n",
|
||||
" <td>Djuricic</td>\n",
|
||||
" <td>Leris</td>\n",
|
||||
" <td>65.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>10</th>\n",
|
||||
" <td>Caputo</td>\n",
|
||||
" <td>Montevago</td>\n",
|
||||
" <td>60.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>11</th>\n",
|
||||
" <td>Di Francesco F.</td>\n",
|
||||
" <td>Banda</td>\n",
|
||||
" <td>55.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>12</th>\n",
|
||||
" <td>Colombo</td>\n",
|
||||
" <td>Ceesay</td>\n",
|
||||
" <td>55.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>13</th>\n",
|
||||
" <td>Gonzalez J.</td>\n",
|
||||
" <td>Bistrovic</td>\n",
|
||||
" <td>60.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>14</th>\n",
|
||||
" <td>Lykogiannis</td>\n",
|
||||
" <td>Cambiaso</td>\n",
|
||||
" <td>55.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>15</th>\n",
|
||||
" <td>Barrow</td>\n",
|
||||
" <td>Orsolini</td>\n",
|
||||
" <td>55.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>16</th>\n",
|
||||
" <td>Ferguson</td>\n",
|
||||
" <td>Schouten</td>\n",
|
||||
" <td>55.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>17</th>\n",
|
||||
" <td>Traore' Hj.</td>\n",
|
||||
" <td>Berardi</td>\n",
|
||||
" <td>55.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>18</th>\n",
|
||||
" <td>Rogerio</td>\n",
|
||||
" <td>Kyriakopoulos</td>\n",
|
||||
" <td>60.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>19</th>\n",
|
||||
" <td>Djimsiti</td>\n",
|
||||
" <td>Scalvini</td>\n",
|
||||
" <td>60.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>20</th>\n",
|
||||
" <td>Zapata D.</td>\n",
|
||||
" <td>Hojlund</td>\n",
|
||||
" <td>60.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>21</th>\n",
|
||||
" <td>Pasalic</td>\n",
|
||||
" <td>Malinovskyi</td>\n",
|
||||
" <td>55.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>22</th>\n",
|
||||
" <td>Bastoni</td>\n",
|
||||
" <td>Acerbi</td>\n",
|
||||
" <td>55.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>23</th>\n",
|
||||
" <td>Brozovic</td>\n",
|
||||
" <td>Mkhitaryan</td>\n",
|
||||
" <td>55.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>24</th>\n",
|
||||
" <td>Skriniar</td>\n",
|
||||
" <td>D'ambrosio</td>\n",
|
||||
" <td>65.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>25</th>\n",
|
||||
" <td>Lazovic</td>\n",
|
||||
" <td>Depaoli</td>\n",
|
||||
" <td>55.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>26</th>\n",
|
||||
" <td>Verdi</td>\n",
|
||||
" <td>Hongla</td>\n",
|
||||
" <td>60.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>27</th>\n",
|
||||
" <td>Dawidowicz</td>\n",
|
||||
" <td>Hien</td>\n",
|
||||
" <td>60.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>28</th>\n",
|
||||
" <td>Verde</td>\n",
|
||||
" <td>Gyasi</td>\n",
|
||||
" <td>55.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>29</th>\n",
|
||||
" <td>Bastoni S.</td>\n",
|
||||
" <td>Amian</td>\n",
|
||||
" <td>55.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>30</th>\n",
|
||||
" <td>Carlos Augusto</td>\n",
|
||||
" <td>D'alessandro</td>\n",
|
||||
" <td>60.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>31</th>\n",
|
||||
" <td>Birindelli</td>\n",
|
||||
" <td>Ciurria</td>\n",
|
||||
" <td>60.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>32</th>\n",
|
||||
" <td>Petagna</td>\n",
|
||||
" <td>Gytkjaer</td>\n",
|
||||
" <td>55.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>33</th>\n",
|
||||
" <td>Caldirola</td>\n",
|
||||
" <td>Carboni</td>\n",
|
||||
" <td>65.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>34</th>\n",
|
||||
" <td>Lovato</td>\n",
|
||||
" <td>Bronn</td>\n",
|
||||
" <td>55.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>35</th>\n",
|
||||
" <td>Piatek</td>\n",
|
||||
" <td>Bonazzoli</td>\n",
|
||||
" <td>55.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>36</th>\n",
|
||||
" <td>Candreva</td>\n",
|
||||
" <td>Bradaric</td>\n",
|
||||
" <td>55.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>37</th>\n",
|
||||
" <td>Zalewski</td>\n",
|
||||
" <td>El Shaarawy</td>\n",
|
||||
" <td>60.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>38</th>\n",
|
||||
" <td>Volpato</td>\n",
|
||||
" <td>Dybala</td>\n",
|
||||
" <td>55.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>39</th>\n",
|
||||
" <td>Matic</td>\n",
|
||||
" <td>Camara Ma.</td>\n",
|
||||
" <td>55.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>40</th>\n",
|
||||
" <td>Vojvoda</td>\n",
|
||||
" <td>Singo</td>\n",
|
||||
" <td>60.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>41</th>\n",
|
||||
" <td>Sanabria</td>\n",
|
||||
" <td>Pellegri</td>\n",
|
||||
" <td>55.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>42</th>\n",
|
||||
" <td>Miranchuk</td>\n",
|
||||
" <td>Radonjic</td>\n",
|
||||
" <td>55.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>43</th>\n",
|
||||
" <td>Kjaer</td>\n",
|
||||
" <td>Gabbia</td>\n",
|
||||
" <td>55.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>44</th>\n",
|
||||
" <td>De Ketelaere</td>\n",
|
||||
" <td>Diaz B.</td>\n",
|
||||
" <td>55.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>45</th>\n",
|
||||
" <td>Bennacer</td>\n",
|
||||
" <td>Pobega</td>\n",
|
||||
" <td>60.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>46</th>\n",
|
||||
" <td>Martinez Quarta</td>\n",
|
||||
" <td>Igor</td>\n",
|
||||
" <td>55.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>47</th>\n",
|
||||
" <td>Bonaventura</td>\n",
|
||||
" <td>Mandragora</td>\n",
|
||||
" <td>55.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>48</th>\n",
|
||||
" <td>Dodo'</td>\n",
|
||||
" <td>Venuti</td>\n",
|
||||
" <td>55.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>49</th>\n",
|
||||
" <td>Ikone'</td>\n",
|
||||
" <td>Saponara</td>\n",
|
||||
" <td>55.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>50</th>\n",
|
||||
" <td>Locatelli</td>\n",
|
||||
" <td>Paredes</td>\n",
|
||||
" <td>60.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>51</th>\n",
|
||||
" <td>Milik</td>\n",
|
||||
" <td>Vlahovic</td>\n",
|
||||
" <td>65.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>52</th>\n",
|
||||
" <td>Miretti</td>\n",
|
||||
" <td>Di Maria</td>\n",
|
||||
" <td>55.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>53</th>\n",
|
||||
" <td>Immobile</td>\n",
|
||||
" <td>Cancellieri</td>\n",
|
||||
" <td>60.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>54</th>\n",
|
||||
" <td>Vecino</td>\n",
|
||||
" <td>Luis Alberto</td>\n",
|
||||
" <td>55.0</td>\n",
|
||||
" </tr>\n",
|
||||
" </tbody>\n",
|
||||
"</table>\n",
|
||||
"</div>"
|
||||
],
|
||||
"text/plain": [
|
||||
" player1 player2 percentage\n",
|
||||
"0 Lozano Politano 60.0\n",
|
||||
"1 Zambo Anguissa Ndombele' 60.0\n",
|
||||
"2 Mario Rui Olivera 55.0\n",
|
||||
"3 Elmas Raspadori 55.0\n",
|
||||
"4 Beto Success 60.0\n",
|
||||
"5 Lovric Samardzic 55.0\n",
|
||||
"6 Ehizibue Nuytinck 60.0\n",
|
||||
"7 Rincon Vieira 60.0\n",
|
||||
"8 Augello Murru 55.0\n",
|
||||
"9 Djuricic Leris 65.0\n",
|
||||
"10 Caputo Montevago 60.0\n",
|
||||
"11 Di Francesco F. Banda 55.0\n",
|
||||
"12 Colombo Ceesay 55.0\n",
|
||||
"13 Gonzalez J. Bistrovic 60.0\n",
|
||||
"14 Lykogiannis Cambiaso 55.0\n",
|
||||
"15 Barrow Orsolini 55.0\n",
|
||||
"16 Ferguson Schouten 55.0\n",
|
||||
"17 Traore' Hj. Berardi 55.0\n",
|
||||
"18 Rogerio Kyriakopoulos 60.0\n",
|
||||
"19 Djimsiti Scalvini 60.0\n",
|
||||
"20 Zapata D. Hojlund 60.0\n",
|
||||
"21 Pasalic Malinovskyi 55.0\n",
|
||||
"22 Bastoni Acerbi 55.0\n",
|
||||
"23 Brozovic Mkhitaryan 55.0\n",
|
||||
"24 Skriniar D'ambrosio 65.0\n",
|
||||
"25 Lazovic Depaoli 55.0\n",
|
||||
"26 Verdi Hongla 60.0\n",
|
||||
"27 Dawidowicz Hien 60.0\n",
|
||||
"28 Verde Gyasi 55.0\n",
|
||||
"29 Bastoni S. Amian 55.0\n",
|
||||
"30 Carlos Augusto D'alessandro 60.0\n",
|
||||
"31 Birindelli Ciurria 60.0\n",
|
||||
"32 Petagna Gytkjaer 55.0\n",
|
||||
"33 Caldirola Carboni 65.0\n",
|
||||
"34 Lovato Bronn 55.0\n",
|
||||
"35 Piatek Bonazzoli 55.0\n",
|
||||
"36 Candreva Bradaric 55.0\n",
|
||||
"37 Zalewski El Shaarawy 60.0\n",
|
||||
"38 Volpato Dybala 55.0\n",
|
||||
"39 Matic Camara Ma. 55.0\n",
|
||||
"40 Vojvoda Singo 60.0\n",
|
||||
"41 Sanabria Pellegri 55.0\n",
|
||||
"42 Miranchuk Radonjic 55.0\n",
|
||||
"43 Kjaer Gabbia 55.0\n",
|
||||
"44 De Ketelaere Diaz B. 55.0\n",
|
||||
"45 Bennacer Pobega 60.0\n",
|
||||
"46 Martinez Quarta Igor 55.0\n",
|
||||
"47 Bonaventura Mandragora 55.0\n",
|
||||
"48 Dodo' Venuti 55.0\n",
|
||||
"49 Ikone' Saponara 55.0\n",
|
||||
"50 Locatelli Paredes 60.0\n",
|
||||
"51 Milik Vlahovic 65.0\n",
|
||||
"52 Miretti Di Maria 55.0\n",
|
||||
"53 Immobile Cancellieri 60.0\n",
|
||||
"54 Vecino Luis Alberto 55.0"
|
||||
]
|
||||
},
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"groups = soup.findAll('ul', attrs = {'class' : 'ballot-list'})\n",
|
||||
"\n",
|
||||
"ballots = pd.DataFrame(columns = ['player1', 'player2', 'percentage'])\n",
|
||||
"for i in range (len(groups)):\n",
|
||||
" players = groups[i].findAll('a', attrs = {'class' : 'player-name'})\n",
|
||||
" percs = groups[i].findAll('strong', attrs = {'class' : 'percentage'})\n",
|
||||
" \n",
|
||||
" player1 = players[0].contents[0].replace('\\n \\n ', '')\n",
|
||||
" player2 = players[1].contents[0].replace('\\n \\n ', '')\n",
|
||||
" perc = float(percs[0].contents[0].replace('%', ''))\n",
|
||||
" \n",
|
||||
" row_df = pd.DataFrame([[player1, player2, perc]], columns = ballots.columns)\n",
|
||||
" \n",
|
||||
" ballots = pd.concat([ballots, row_df], ignore_index = True)\n",
|
||||
" \n",
|
||||
"ballots"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"id": "0171c61d",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<div>\n",
|
||||
"<style scoped>\n",
|
||||
" .dataframe tbody tr th:only-of-type {\n",
|
||||
" vertical-align: middle;\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" .dataframe tbody tr th {\n",
|
||||
" vertical-align: top;\n",
|
||||
" }\n",
|
||||
"\n",
|
||||
" .dataframe thead th {\n",
|
||||
" text-align: right;\n",
|
||||
" }\n",
|
||||
"</style>\n",
|
||||
"<table border=\"1\" class=\"dataframe\">\n",
|
||||
" <thead>\n",
|
||||
" <tr style=\"text-align: right;\">\n",
|
||||
" <th></th>\n",
|
||||
" <th>starter</th>\n",
|
||||
" <th>percentage</th>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>player</th>\n",
|
||||
" <th></th>\n",
|
||||
" <th></th>\n",
|
||||
" </tr>\n",
|
||||
" </thead>\n",
|
||||
" <tbody>\n",
|
||||
" <tr>\n",
|
||||
" <th>Vicario</th>\n",
|
||||
" <td>1</td>\n",
|
||||
" <td>100.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>Ebuehi</th>\n",
|
||||
" <td>1</td>\n",
|
||||
" <td>100.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>Ismajli</th>\n",
|
||||
" <td>1</td>\n",
|
||||
" <td>100.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>Walukiewicz</th>\n",
|
||||
" <td>1</td>\n",
|
||||
" <td>100.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>Parisi</th>\n",
|
||||
" <td>1</td>\n",
|
||||
" <td>100.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>...</th>\n",
|
||||
" <td>...</td>\n",
|
||||
" <td>...</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>Basic</th>\n",
|
||||
" <td>0</td>\n",
|
||||
" <td>55.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>Bertini</th>\n",
|
||||
" <td>0</td>\n",
|
||||
" <td>10.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>Marcos Antonio</th>\n",
|
||||
" <td>0</td>\n",
|
||||
" <td>50.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>Romero L.</th>\n",
|
||||
" <td>0</td>\n",
|
||||
" <td>50.0</td>\n",
|
||||
" </tr>\n",
|
||||
" <tr>\n",
|
||||
" <th>Cancellieri</th>\n",
|
||||
" <td>0.4</td>\n",
|
||||
" <td>55.0</td>\n",
|
||||
" </tr>\n",
|
||||
" </tbody>\n",
|
||||
"</table>\n",
|
||||
"<p>449 rows × 2 columns</p>\n",
|
||||
"</div>"
|
||||
],
|
||||
"text/plain": [
|
||||
" starter percentage\n",
|
||||
"player \n",
|
||||
"Vicario 1 100.0\n",
|
||||
"Ebuehi 1 100.0\n",
|
||||
"Ismajli 1 100.0\n",
|
||||
"Walukiewicz 1 100.0\n",
|
||||
"Parisi 1 100.0\n",
|
||||
"... ... ...\n",
|
||||
"Basic 0 55.0\n",
|
||||
"Bertini 0 10.0\n",
|
||||
"Marcos Antonio 0 50.0\n",
|
||||
"Romero L. 0 50.0\n",
|
||||
"Cancellieri 0.4 55.0\n",
|
||||
"\n",
|
||||
"[449 rows x 2 columns]"
|
||||
]
|
||||
},
|
||||
"execution_count": 6,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"for i in range(ballots.shape[0]):\n",
|
||||
" p1 = ballots['player1'][i]\n",
|
||||
" p2 = ballots['player2'][i]\n",
|
||||
" \n",
|
||||
" perc = float(ballots['percentage'][i])\n",
|
||||
" \n",
|
||||
" probables.at[p1, 'starter'] = perc/100\n",
|
||||
" probables.at[p2, 'starter'] = 1 - perc/100\n",
|
||||
" \n",
|
||||
"probables"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
"id": "8b5468aa",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"probables.to_excel('mid_outputs/match_probable_players.xlsx') "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "cf992051",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"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.9.13"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2022 Giuseppe Musicco
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+165
File diff suppressed because one or more lines are too long
@@ -0,0 +1,76 @@
|
||||
<font size = "+3"><b>fantabeto</b></size>
|
||||
|
||||
Fantacalcio Bayesian Estimated Team's Outcome
|
||||
|
||||
<i>Machine learning model for predicting Serie A players performance in a match, in terms of Fantacalcio (italian fantasy football) scores.</i>
|
||||
|
||||
The aim of this project is to predict Fantacalcio (Serie A fantasy football) player performances (vote and fantavote, respectively their match rating and that summed to the bonus/malus given by goals, assists and cards), using players and teams data from http://fantacalcio.it and http://fbref.com.
|
||||
|
||||
"outputs" folder contains predictions for the next Serie A matchdays, and an excel file for analysis. A list of players can be inserted to help selecting an optimal line-up.
|
||||
|
||||

|
||||
|
||||
Two neural network models are trained for predicting vote and fantavote for outfield players and goalkeepers, for which the clean sheet probability is also an output.
|
||||
The outputs of these models are not raw predictions, but probability distributions, in the form of SinhArcsinh, which is a skewed distribution, meaning that the probability density is asymmetric.
|
||||
For predicting clean sheet probability, a Bernoulli distribution is instead used (a sample of which would be clean sheet = 1, with a given probability p, or clean sheet = 0 with probability 1-p)
|
||||
|
||||
See the following code and plot to show an example of vote and fantavote probability distributions.
|
||||
In this case, the player would be an attacking one, whose fantavote distribution is very skewed to the right (it is very more probable to score a goal and receive a 10 = 7+3 fantavote, than having an awful performance with a 4 fantavote!).
|
||||
|
||||
|
||||
```python
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
def sinh_archsinh_pdf(x, mu, sigma, eps, delta):
|
||||
mul = 2 / np.sinh( np.arcsinh(2) * delta)
|
||||
z = (x - mu) / (sigma*mul)
|
||||
S = np.sinh( -eps + (1/delta) * np.arcsinh(z))
|
||||
return np.exp(-0.5 * S * S) * np.sqrt(1 + S * S) / ( sigma * mul * delta ) / np.sqrt(1 + z * z) / np.sqrt(2 * np.pi)
|
||||
|
||||
x = np.arange(start = 0, stop = 30, step = 0.001)
|
||||
pxv = sinh_archsinh_pdf(x, 6.06, 0.62, 0.33, 1.06)
|
||||
pxf = sinh_archsinh_pdf(x, 5.6657, 1.224146, 0.795868, 1.9983)
|
||||
plt.plot(x, pxv, label = 'vote', color = 'b')
|
||||
plt.plot(x, pxf, label = 'fantavote', color = 'g')
|
||||
plt.fill_between(x, pxv, color = 'lightblue')
|
||||
plt.fill_between(x, pxf, color = 'lightgreen')
|
||||
mv = np.average(x, weights = pxv)
|
||||
mf = np.average(x, weights = pxf)
|
||||
plt.vlines(x = mv, color = 'b', ymin = 0, ymax = 3, linestyle = 'dashed', label = 'mean vote = ' + '{:.2f}'.format(mv))
|
||||
plt.vlines(x = mf, color = 'g', ymin = 0, ymax = 3, linestyle = 'dashed', label = 'mean fantavote = ' + '{:.2f}'.format(mf))
|
||||
plt.legend()
|
||||
plt.xlim([0, 20])
|
||||
plt.ylim([0, 1])
|
||||
plt.ylabel('Probability Density')
|
||||
plt.xlabel('Vote')
|
||||
plt.title('Beto (A) estimated performance')
|
||||
plt.show()
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||

|
||||
|
||||
|
||||
|
||||
There is code also for computing the expected points outcome of a particular line-up, by sampling multiple times from the players' points distribution and considering bonus for Defense Modifier ("Modificatore") and Clean Sheet. This leads to estimating the team's points probability distribution.
|
||||
|
||||

|
||||
|
||||
Credits:
|
||||
|
||||
http://Fantacalcio.it - The game! And of course, a lot of data, including votes, players list and probable line-ups.
|
||||
|
||||
http://FBRef.com - Plenty of stats for football players and teams.
|
||||
|
||||
https://github.com/amiles2233/ff_prob - Inspiration, for using Tensorflow Probability and Bayesian Neural Networks for this task.
|
||||
|
||||
https://github.com/parth1902/Scrape-FBref-data - FBref data scraping code.
|
||||
|
||||
#fantacalcio #fantasy-football #serie-a
|
||||
|
||||
#machine-learning #ai #neural-networks
|
||||
|
||||
#python #tensorflow #tensorflow-probability
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 38 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 40 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 103 KiB |
@@ -0,0 +1,11 @@
|
||||
player,alike
|
||||
Doig,Lazovic
|
||||
Origi,Rebic
|
||||
Fagioli,Henderson L.
|
||||
Di Maria,Chiesa
|
||||
Ranocchia F.,Henderson L.
|
||||
Piccoli,Lasagna
|
||||
Alvarez A.,Raspadori
|
||||
Ballo-Toure',Calabria
|
||||
Ferguson,Svanberg
|
||||
Bijol,Rodrigo Becao
|
||||
@@ -0,0 +1,12 @@
|
||||
FROM,TO,TEAM
|
||||
stigard,Ostigard,Napoli
|
||||
Min-jae,Kim,Napoli
|
||||
Hjlund,Hojlund,Atalanta
|
||||
Gytkjr,Gytkjaer,Monza
|
||||
Carlos,Augusto,Monza
|
||||
Mhle,Maehle,Atalanta
|
||||
Kjr,Kjaer,Milan
|
||||
uricic,Djuricic,Sampdoria
|
||||
uric,Djuric,Hellas Verona
|
||||
Arthur,Cabral,Fiorentina
|
||||
Martinez,Alvarez,Sassuolo
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user