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

Python Script

The document outlines a Python script that processes shipping data from CSV files and stores it in an SQLite database. It involves loading data, inserting unique products into a database, and aggregating quantities from one of the spreadsheets before merging with another. Finally, it commits the changes to the database and closes the connection.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

Python Script

The document outlines a Python script that processes shipping data from CSV files and stores it in an SQLite database. It involves loading data, inserting unique products into a database, and aggregating quantities from one of the spreadsheets before merging with another. Finally, it commits the changes to the database and closes the connection.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

import pandas as pd

import sqlite3
from collections import Counter

conn=[Link]("shipment_database.db")
cur=[Link]()

# Load CSVs
s0=pd.read_csv("data/shipping_data_0.csv")
s1=pd.read_csv("data/shipping_data_1.csv")
s2=pd.read_csv("data/shipping_data_2.csv")

# Insert unique products


products=sorted(s1["product"].unique())
product_map={}
for p in products:
[Link]("INSERT INTO product(name) VALUES(?)",(p,))
product_map[p]=[Link]

# Spreadsheet0 self contained (one row=one shipment)


for _,r in [Link]():
pid=product_map.setdefault(r["product"],None)

# Aggregate spreadsheet1 quantities


qty=[Link](["shipment_identifier","product"]).size().reset_index(name="quantity")
merged=[Link](s2,on="shipment_identifier")
for _,r in [Link]():
[Link]("INSERT INTO shipment(product_id,quantity,origin,destination) VALUES(?,?,?,?)",(produ
[Link]();[Link]()

You might also like