Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Python #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions Python
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import pandas as pd
import sqlite3

# Step 1: Clone the repository and navigate to the directory
# Clone the repository: https://github.com/theforage/forage-walmart-task-4

# Step 2: Load data from spreadsheets into DataFrames
spreadsheet_0 = pd.read_excel('path_to_spreadsheet_0.xlsx')
spreadsheet_1 = pd.read_excel('path_to_spreadsheet_1.xlsx')
spreadsheet_2 = pd.read_excel('path_to_spreadsheet_2.xlsx')

# Step 3: Create a connection to the SQLite database
conn = sqlite3.connect('walmart_shipping.db')
cursor = conn.cursor()

# Step 4: Insert data from Spreadsheet 0 directly into the database
spreadsheet_0.to_sql('Table0', conn, if_exists='replace', index=False)

# Step 5: Process and insert data from Spreadsheet 1
for index, row in spreadsheet_1.iterrows():
shipping_identifier = row['shipping_identifier']
product_name = row['product_name']
quantity = row['quantity']

# Calculate quantity of goods in the shipment (you may need additional logic)
# quantity = ...

# Insert data into the database
cursor.execute("INSERT INTO Table1 (shipping_identifier, product_name, quantity) VALUES (?, ?, ?)",
(shipping_identifier, product_name, quantity))

# Step 6: Extract origin and destination data from Spreadsheet 2
origin_destination_data = {}
for index, row in spreadsheet_2.iterrows():
shipping_identifier = row['shipping_identifier']
origin = row['origin']
destination = row['destination']

origin_destination_data[shipping_identifier] = {'origin': origin, 'destination': destination}

# Step 7: Update entries in the database with origin and destination information
for shipping_identifier, data in origin_destination_data.items():
origin = data['origin']
destination = data['destination']

cursor.execute("UPDATE Table1 SET origin = ?, destination = ? WHERE shipping_identifier = ?",
(origin, destination, shipping_identifier))

# Commit changes and close the database connection
conn.commit()
conn.close()