Walmart Module4
Walmart Module4
import csv
# Read the data from the CSV file and insert it into the database
with open('shipping_data_0.csv', 'r') as f:
# Skip the header row
next(f)
# Loop through each line in the file
for line in f:
# Split the line into fields
fields = line.strip().split(',')
# Insert the data into the table
c.execute('''INSERT INTO civ_data
(origin_warehouse, destination_store, product, on_time, product_quantity, driver_identifier)
VALUES (?, ?, ?, ?, ?, ?)''',
(fields[0], fields[1], fields[2], int(fields[3]), int(fields[4]), fields[5]))
# Read data from spreadsheet 2 and update the 'products' table with shipment details
with open('shipping_data_2.csv') as file:
reader = csv.reader(file)
for row in reader:
shipment_id, origin_warehouse, destination_store, driver_identifier = row
c.execute('''
UPDATE products
SET shipment_id=?, quantity=(
SELECT COUNT(*) FROM products WHERE shipment_id=?
)
WHERE shipment_id=?
''', (shipment_id, shipment_id, shipment_id))