Popularea bazei de date

Introducere în baze de date în Python

Jason Myers

Co-Author of Essential SQLAlchemy and Software Engineer

Partea 2: popularea bazei de date

  • Încărcați un fișier CSV într-o listă de valori
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)
Introducere în baze de date în Python

Partea 2: popularea bazei de date

  • Inserați lista de valori în tabelul census
from sqlalchemy import insert

stmt = insert(employees)
result_proxy = connection.execute(stmt, values_list) print(result_proxy.rowcount)
2
Introducere în baze de date în Python

Să exersăm!

Introducere în baze de date în Python

Preparing Video For Download...