# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

import pandas as pd
import sqlite3 as sql

conn = sql.connect('nba.db')
action = conn.cursor()

nba = pd.read_csv('nba_draft.csv')

type(nba)
nba.info()

nba = nba[['player', 'draft_yr', 'pk', 'team', 'college', 
           'yrs', 'games', 'minutes_played','pts', 'fg_percentage', 'ft_percentage']]

action.execute("DROP TABLE IF EXISTS  players ")
action.execute("""CREATE TABLE players(
                    player text,
                    draft_yr integer,
                    pk integer,
                    team text,
                    college text,
                    yrs integer,
                    games integer,
                    minutes_played integer,
                    pts integer,
                    fg_percentage real,
                    ft_percentage real)""")
conn.commit()

nba.to_sql('players', conn, if_exists='append', index=False)

action.execute("SELECT * FROM players")

action.fetchmany(3)

action.execute("SELECT Count(*) FROM players")
action.fetchall()

action.execute("SELECT avg(games) FROM players")
action.fetchall()

action.execute("SELECT avg(games) FROM players WHERE pk <= 10")
action.fetchall()



action.execute("SELECT DISTINCT college FROM players ORDER BY college")
action.fetchall()

action.execute("SELECT count(DISTINCT college) FROM players ORDER BY college")
action.fetchall()

action.execute("SELECT player FROM players WHERE college = 'Yale University' ORDER BY college")
action.fetchall()

action.execute("SELECT avg(fg_percentage) FROM players WHERE pk <= 10")
action.fetchone()

action.execute("SELECT avg(fg_percentage) FROM players")
action.fetchone()

action.execute("SELECT max(fg_percentage) FROM players")
action.fetchone()

action.execute("SELECT avg(fg_percentage) FROM players WHERE games > 187")
action.fetchone()

action.execute("SELECT player FROM players WHERE yrs > 20 ORDER BY player")
action.fetchall()



StarcoderdataJupyterScriptsDedupFiltered