Fix docstring indentation and add comments in load_games function
- Adjusted docstring formatting for clarity and correctness - Added inline comments explaining key steps in load_games function
This commit is contained in:
@@ -41,7 +41,7 @@ def load_games(
|
|||||||
DataFrame with columns Date, HomeTeam, AwayTeam, HomeRuns, AwayRuns, Margin, Result
|
DataFrame with columns Date, HomeTeam, AwayTeam, HomeRuns, AwayRuns, Margin, Result
|
||||||
"""
|
"""
|
||||||
df = pd.read_csv(inp)
|
df = pd.read_csv(inp)
|
||||||
|
# Choose identifiers
|
||||||
# Determine team ID columns based on input param
|
# Determine team ID columns based on input param
|
||||||
home_id_col = "home_name" if team_id == "names" else "home_slug"
|
home_id_col = "home_name" if team_id == "names" else "home_slug"
|
||||||
away_id_col = "away_name" if team_id == "names" else "away_slug"
|
away_id_col = "away_name" if team_id == "names" else "away_slug"
|
||||||
@@ -49,12 +49,11 @@ def load_games(
|
|||||||
if c not in df.columns:
|
if c not in df.columns:
|
||||||
raise ValueError(f"Missing required column: {c}")
|
raise ValueError(f"Missing required column: {c}")
|
||||||
|
|
||||||
|
# Optional status filter (helps exclude postponed/canceled)
|
||||||
# Filter for final_status if provided to exclude e.g. postponed games
|
# Filter for final_status if provided to exclude e.g. postponed games
|
||||||
if final_status is not None and "status" in df.columns:
|
if final_status is not None and "status" in df.columns:
|
||||||
df = df[df["status"].astype(str).str.lower() == str(final_status).lower()]
|
df = df[df["status"].astype(str).str.lower() == str(final_status).lower()]
|
||||||
|
|
||||||
|
|
||||||
# Convert run columns to numeric, drop rows with missing runs or teams
|
# Convert run columns to numeric, drop rows with missing runs or teams
|
||||||
df = df.copy()
|
df = df.copy()
|
||||||
df["home_runs"] = pd.to_numeric(df["home_runs"], errors="coerce")
|
df["home_runs"] = pd.to_numeric(df["home_runs"], errors="coerce")
|
||||||
|
|||||||
Reference in New Issue
Block a user