| 123456789101112131415161718192021222324252627282930313233343536373839 | import sqlite3import csv# Define the input CSV file and the SQLite database fileinput_csv = 'nba_roster.csv'database_file = 'nba_roster.db'# Connect to the SQLite databaseconn = sqlite3.connect(database_file)cursor = conn.cursor()# Create a table to store the datacursor.execute('''CREATE TABLE IF NOT EXISTS nba_roster (                    Team TEXT,                    NAME TEXT,                    Jersey TEXT,                    POS TEXT,                    AGE INT,                    HT TEXT,                    WT TEXT,                    COLLEGE TEXT,                    SALARY TEXT                )''')# Read data from the CSV file and insert it into the SQLite tablewith open(input_csv, 'r', newline='') as csvfile:    csv_reader = csv.reader(csvfile)    next(csv_reader)  # Skip the header row        for row in csv_reader:        cursor.execute('INSERT INTO nba_roster VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)', row)# Commit the changes and close the database connectionconn.commit()conn.close()print(f'Data from {input_csv} has been successfully imported into {database_file}')
 |