Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions football_matches/scraping.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,15 @@
" data = requests.get(f\"https://fbref.com{links[0]}\")\n",
" shooting = pd.read_html(data.text, match=\"Shooting\")[0]\n",
" shooting.columns = shooting.columns.droplevel()\n",
" \n",
" newShootingCols = [\"Date\", \"Sh\", \"SoT\", \"Dist\", \"FK\", \"PK\", \"PKatt\"]\n",
" \n",
" # In less recent seasons, some of the expected shooting columns might not be present.\n",
" # This loop avoids a merging error by creating empty columns\n",
" for newCol in newShootingCols:\n",
" if newCol not in shooting.columns:\n",
" shooting[newCol] = np.nan\n",
" \n",
" try:\n",
" team_data = matches.merge(shooting[[\"Date\", \"Sh\", \"SoT\", \"Dist\", \"FK\", \"PK\", \"PKatt\"]], on=\"Date\")\n",
" except ValueError:\n",
Expand Down