nba / scripts /nba_standings.py
yetarnished's picture
Create nba_standings.py
d757142 verified
Raw
History Blame Contribute Delete
1.35 kB
from nba_api.stats.endpoints import leaguestandings
import pandas as pd
print("🏆 CONFERENCE STANDINGS")
print("=" * 50)
try:
# Fetch Data
standings = leaguestandings.LeagueStandings()
df = standings.standings.get_data_frame()
# Organize columns
cols = ['Conference', 'PlayoffRank', 'TeamCity', 'TeamName', 'WINS', 'LOSSES', 'WinPCT']
df = df[cols]
# Process West
print("\nWestern Conference")
print("-" * 50)
print(f"{'#':<3} | {'TEAM':<20} | {'W':<3} | {'L':<3} | {'PCT'}")
print("-" * 50)
west = df[df['Conference'] == 'West'].sort_values(by='PlayoffRank')
for _, row in west.iterrows():
team = f"{row['TeamCity']} {row['TeamName']}"
print(f"{row['PlayoffRank']:<3} | {team:<20} | {row['WINS']:<3} | {row['LOSSES']:<3} | {row['WinPCT']:.3f}")
# Process East
print("\n\nEastern Conference")
print("-" * 50)
print(f"{'#':<3} | {'TEAM':<20} | {'W':<3} | {'L':<3} | {'PCT'}")
print("-" * 50)
east = df[df['Conference'] == 'East'].sort_values(by='PlayoffRank')
for _, row in east.iterrows():
team = f"{row['TeamCity']} {row['TeamName']}"
print(f"{row['PlayoffRank']:<3} | {team:<20} | {row['WINS']:<3} | {row['LOSSES']:<3} | {row['WinPCT']:.3f}")
except Exception as e:
print(f"Error fetching standings: {e}")