0% found this document useful (0 votes)
4 views1 page

Populate SQLite with Excel Data

Uploaded by

mamalal346
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Populate SQLite with Excel Data

Uploaded by

mamalal346
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

import pandas as pd

import sqlite3

# Connect to the SQLite database


conn = [Link]('[Link]')
cursor = [Link]()

# Step 1: Load the spreadsheets


spreadsheet0 = pd.read_excel('[Link]')
spreadsheet1 = pd.read_excel('[Link]')
spreadsheet2 = pd.read_excel('[Link]')

# Step 2: Insert Spreadsheet 0 data into the database


def insert_spreadsheet0():
for index, row in [Link]():
[Link]("""
INSERT INTO products (product_name, manufacturer, weight, flavor,
target_health_condition)
VALUES (?, ?, ?, ?, ?)
""", (row['name'], row['manufacturer'], row['weight'], row['flavor'],
row['target_health_condition']))
[Link]()

# Step 3: Combine data from Spreadsheet 1 and 2


def process_spreadsheet1_and_2():
# Merge spreadsheet1 and spreadsheet2 based on the shipping identifier
merged_data = [Link](spreadsheet1, spreadsheet2, on='shipping_id')

for index, row in merged_data.iterrows():


# Calculate quantity and prepare for insertion
quantity = row['quantity']

# Insert shipment data


[Link]("""
INSERT INTO shipments (product_name, origin, destination, quantity)
VALUES (?, ?, ?, ?)
""", (row['product_name'], row['origin'], row['destination'], quantity))

[Link]()

# Step 4: Execute the functions


insert_spreadsheet0()
process_spreadsheet1_and_2()

# Close the database connection


[Link]()

print("Database population completed successfully.")

You might also like