人口普查案例研究

Python 中的数据库入门

Jason Myers

Co-Author of Essential SQLAlchemy and Software Engineer

人口普查案例研究

  • 准备 SQLAlchemy 和数据库
  • 将数据加载到数据库
  • 用查询解决数据科学问题
Python 中的数据库入门

第 1 部分:准备 SQLAlchemy 和数据库

  • 创建引擎和 MetaData 对象
from sqlalchemy import create_engine, MetaData
engine = create_engine('sqlite:///census_nyc.sqlite')
metadata = MetaData()
Python 中的数据库入门

第 1 部分:准备 SQLAlchemy 和数据库

  • 创建并保存 census 表
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)
Python 中的数据库入门

让我们来练习!

Python 中的数据库入门

Preparing Video For Download...