diff --git a/docs/examples/Home Team Win-Loss Modeling/Home Team Win-Loss Data Prep.ipynb b/docs/examples/Home Team Win-Loss Modeling/Home Team Win-Loss Data Prep.ipynb index e131b3ba..b3de7d96 100644 --- a/docs/examples/Home Team Win-Loss Modeling/Home Team Win-Loss Data Prep.ipynb +++ b/docs/examples/Home Team Win-Loss Modeling/Home Team Win-Loss Data Prep.ipynb @@ -20,7 +20,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -46,7 +46,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -67,7 +67,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -115,14 +115,14 @@ " teamLookup = pd.DataFrame(teams.get_teams())\n", "\n", " # Get teams schedule for each team for each season\n", - " scheduleFrame = pd.DataFrame()\n", + " scheduleFrames = []\n", "\n", " for season in seasons:\n", " for id in teamLookup[\"id\"]:\n", " time.sleep(1)\n", - " scheduleFrame = scheduleFrame.append(\n", - " getRegularSeasonSchedule(season, id, seasonType)\n", - " )\n", + " scheduleFrames.append(getRegularSeasonSchedule(season, id, seasonType))\n", + "\n", + " scheduleFrame = pd.concat(scheduleFrames, ignore_index=True)\n", "\n", " scheduleFrame[\"GAME_DATE\"] = pd.to_datetime(\n", " scheduleFrame[\"MATCHUP\"].map(getGameDate)\n", @@ -282,9 +282,14 @@ "\n", " i = int(len(gameLogs) / 2) # Can use a previously completed gameLog dataset\n", "\n", + " # Start from any previously completed gameLogs, then collect each game's\n", + " # frame in a list and concat once at the end (instead of growing the\n", + " # DataFrame every iteration).\n", + " gameLogsList = [gameLogs] if not gameLogs.empty else []\n", + "\n", " while i < len(scheduleFrame):\n", " time.sleep(1)\n", - " gameLogs = gameLogs.append(\n", + " gameLogsList.append(\n", " getSingleGameMetrics(\n", " scheduleFrame.at[i, \"GAME_ID\"],\n", " scheduleFrame.at[i, \"HOME_TEAM_ID\"],\n", @@ -295,8 +300,6 @@ " )\n", " )\n", "\n", - " gameLogs = gameLogs.reset_index(drop=True)\n", - "\n", " end = time.perf_counter_ns()\n", "\n", " # Output time it took to load x amount of records\n", @@ -306,6 +309,8 @@ "\n", " i += 1\n", "\n", + " gameLogs = pd.concat(gameLogsList, ignore_index=True)\n", + "\n", " # Get Table Level Aggregation Columns\n", " getHomeAwayFlag(gameLogs)\n", " gameLogs = getHomeWinPctg(gameLogs)\n", @@ -327,7 +332,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "2.7492755266666666\n" + "2.7116616116666665\n" ] } ], @@ -484,46 +489,9 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "0 0.027592645000000002\n", - "100 3.761211635\n", - "200 7.446148228333333\n", - "300 10.91657379\n", - "400 14.178322275\n", - "500 17.562468318333334\n", - "600 22.57064343333333\n", - "700 28.885029056666667\n", - "800 32.53894844333333\n", - "900 36.77510828333333\n", - "1000 41.57496655333333\n", - "1100 45.66484153166667\n", - "1200 48.904151811666665\n", - "1300 52.46264781666666\n", - "1400 55.85839063666666\n", - "1500 60.04402927833333\n", - "1600 64.00290142\n", - "1700 67.65499090166666\n", - "1800 71.13305232833333\n", - "1900 75.12400890166667\n", - "2000 78.45767208000001\n", - "2100 82.388200135\n", - "2200 85.89361625166666\n", - "2300 90.73073644\n", - "2400 92.95489135999999\n", - "2500 95.15283247333333\n", - "2600 97.83685436833333\n", - "2700 101.011523535\n", - "2800 104.15464245833333\n", - "2900 108.15016159333332\n" - ] - } - ], + "outputs": [], "source": [ "# Create the gameLogs DataFrame\n", "gameLogs = pd.DataFrame()\n", @@ -2212,7 +2180,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.5" + "version": "3.11.0" } }, "nbformat": 4,