Census case study

Introduction to Databases in Python

Jason Myers

Co-Author of Essential SQLAlchemy and Software Engineer

Census case study

  • Preparing SQLAlchemy and the database
  • Loading data into the database
  • Solving data science problems with queries
Introduction to Databases in Python

Part 1: preparing SQLAlchemy and the database

  • Create an engine and MetaData object
from sqlalchemy import create_engine, MetaData
engine = create_engine('sqlite:///census_nyc.sqlite')
metadata = MetaData()
Introduction to Databases in Python

Part 1: preparing SQLAlchemy and the database

  • Create and save the census table
from sqlalchemy import (Table, Column, String, 
       Integer, Decimal, Boolean)

employees = Table('employees', metadata, Column('id', Integer()), Column('name', String(255)), Column('salary', Decimal()), Column('active', Boolean()))
metadata.create_all(engine)
Introduction to Databases in Python

Let's practice!

Introduction to Databases in Python

Preparing Video For Download...