sql from jupyter notebooks
snippet in sql

sql from jupyter notebooks

user9102

# import packages
import pandas as pd
import sqlite3 

# connect database and create cursor
conn = sqlite3.connect('data.sqlite')
cur = conn.cursor()

# executing the query
cur.execute("""SELECT * FROM employees LIMIT 5;""")

# creating a dataframe object
df = pd.DataFrame(cur.fetchall())

# find database attributes from cursor.description to use as column names
cur.description

# creating dataframe columns
df.columns = [x[0] for x in cur.description]
df.head()