Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix when shooting column FK, is not found #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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