In [4]:
import sqlite3
conn = sqlite3.connect('mtcars.sqlite')
c = conn.cursor()
In [5]:
# create and execute our query
cylinders = 4
cursor = c.execute("SELECT * FROM results WHERE cyl = {0}".format(cylinders))
In [6]:
# fetch a list of the column names
column_names = list(map(lambda x: x[0], cursor.description))
# fetch all rows and map column names onto them
rows = map(lambda x: dict(zip(column_names, x)), cursor.fetchall())
# print the name and MPG for each result
for row in rows:
print("{name}:\t{mpg}".format(**row))
In [7]:
import pandas as pd
df = pd.read_sql_query("SELECT * from results", conn)
print(df.head())
In [ ]: