Nạp dữ liệu vào cơ sở dữ liệu

Nhập môn Cơ sở dữ liệu với Python

Jason Myers

Co-Author of Essential SQLAlchemy and Software Engineer

Phần 2: nạp dữ liệu vào cơ sở dữ liệu

  • Nạp tệp CSV vào danh sách giá trị
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)
Nhập môn Cơ sở dữ liệu với Python

Phần 2: Nạp dữ liệu vào cơ sở dữ liệu

  • Chèn danh sách giá trị vào bảng census
from sqlalchemy import insert

stmt = insert(employees)
result_proxy = connection.execute(stmt, values_list) print(result_proxy.rowcount)
2
Nhập môn Cơ sở dữ liệu với Python

Ayo berlatih!

Nhập môn Cơ sở dữ liệu với Python

Preparing Video For Download...