<jupyter_start><jupyter_text>Filling a Table vs. Printing Values<jupyter_code>import numpy as np

prng = np.random.RandomState(42)
numbers = prng.uniform(low=10.0, high=25.0, size=1000000)
%%timeit

connection = sqlite3.connect("../data/original.db")
cursor = connection.cursor()
cursor.execute("DROP TABLE IF EXISTS Pressure;")
cursor.execute("CREATE TABLE Pressure (reading float not null);")

query = "INSERT INTO Pressure values (?);"
for number in numbers:
    cursor.execute(query, [number])

cursor.close()
connection.commit()
connection.close
%%timeit

with open("../data/original.txt", 'w') as out:
    for number in numbers:
        out.write(f"{number}\n")<jupyter_output><empty_output><jupyter_text>Filtering in SQL vs. Filtering in Python<jupyter_code>%%timeit

original_connection = sqlite3.connect("../data/original.db")
original_cursor = original_connection.cursor()
original_cursor.execute("SELECT * FROM Pressure;")
results = original_cursor.fetchall()
original_cursor.close()
original_connection.close()

backup_connection = sqlite3.connect("../data/backup.db")
backup_cursor = backup_connection.cursor()
backup_cursor.execute("DROP TABLE IF EXISTS Pressure;")
backup_cursor.execute("CREATE TABLE Pressure (reading float not null);")

query = "INSERT INTO Pressure values (?);"
for (number,) in results:
    if number > 20.0:
        backup_cursor.execute(query, [number])
    else:
        pass
backup_cursor.close()
backup_connection.commit()
backup_connection.close()
%%timeit

original_connection = sqlite3.connect("../data/original.db")
original_cursor = original_connection.cursor()
original_cursor.execute("SELECT * FROM Pressure WHERE reading > 20.0;")
results = original_cursor.fetchall()
original_cursor.close()
original_connection.close()

backup_connection = sqlite3.connect("../data/backup.db")
backup_cursor = backup_connection.cursor()
backup_cursor.execute("DROP TABLE IF EXISTS Pressure;")
backup_cursor.execute("CREATE TABLE Pressure (reading float not null);")

query = "INSERT INTO Pressure values (?);"
for (number,) in results:
    backup_cursor.execute(query, [number])
    
backup_cursor.close()
backup_connection.commit()
backup_connection.close()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13327330031517334, 'fraction_numerical': 0.01170643854119766, 'mean_word_length': 6.053968253968254, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '223617', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 706, 'n_tokens_neox': 664, 'n_words': 154, 'path': 'introduction-to-sql/notebooks/programming-with-dbs-python.ipynb', 'repo_name': 'haaz77/introduction-to-data-science-workshop', 'size': '2221'}