データベースへの投入

Pythonで学ぶデータベース入門

Jason Myers

Co-Author of Essential SQLAlchemy and Software Engineer

パート2: データベースへの投入

  • CSV を値リストに読み込む
values_list = []
for row in csv_reader:
    data = {'state': row[0], 'sex': row[1], 'age': row[2],
            'pop2000': row[3], 'pop2008': row[4]}
    values_list.append(data)
Pythonで学ぶデータベース入門

パート2: データベースへの投入

  • 値リストを census テーブルに挿入する
from sqlalchemy import insert

stmt = insert(employees)
result_proxy = connection.execute(stmt, values_list) print(result_proxy.rowcount)
2
Pythonで学ぶデータベース入門

Let's practice!

Pythonで学ぶデータベース入門

Preparing Video For Download...