0 / 8 activities
APPLIED DATA ANALYTICS

Data Joining in python — 3 Essential Checks for Better Parcel Pricing

Practice Data Joining in python by stacking two weekly parcel manifests, matching shipments to zone tariffs, and explaining which delivery charges finance can support.

Data AnalyticsPython · pandasMerge & concat
Start the project →
Data Joining in python workflow from two weekly manifests to a priced parcel ledger
01

The real-world scenario

Read the business brief before touching the code.

BUSINESS BRIEF

At Tern Books, a fictional book distributor in Dhaka, the warehouse sends a parcel manifest to finance at the end of each week. The carrier keeps its approved flat fees in a separate zone tariff sheet. On Monday morning, finance needs a two-week delivery-cost estimate. The last report looked tidy, but nobody could trace which shipments had a price and which ones had disappeared during preparation.

The warehouse has supplied two exports with the same columns. Each row identifies one outgoing parcel and its delivery zone. The tariff owner supplied one schedule for the whole reporting period. A zone can serve many parcels, and the schedule may include zones with no shipments. Finance accepts a charge only when the parcel’s zone has one approved fee. Every parcel must still appear in the review, even if its zone is missing from the schedule.

Your handoff will go to two people. The finance lead wants the supported subtotal in BDT and a measure of how much of the workload it covers. The tariff owner needs the exact parcels that require follow-up. Can the team price the whole period today, and can another analyst reproduce your answer from the three source files?

02

Your role

YOUR ASSIGNMENT

Operations Data Analyst

You are the operations data analyst assigned to the warehouse close. Start by deciding what one row represents in each file. Ask the warehouse lead whether parcel identifiers are unique across weeks and ask the tariff owner which schedule applies. These answers determine whether combining two records adds a shipment, attaches a price, or accidentally charges the same parcel twice.

Deliver one reconciled ledger, a zone breakdown for finance and a traceable exception list for the tariff owner. Your Python work must preserve incoming parcel IDs, check how many tariff rows may match one parcel and distinguish a missing price from a zero fee. Explain how much finance can support today and what evidence would allow the remaining parcels to be priced.

03

Identify the problem

How can finance price two weeks of parcels and account for every shipment?

Identify the business outcome, suitable technique and why you would choose it.

04

Investigate

Ask the right questions before developing your solution.

Q01What counts as one supported charge?

One charge represents one shipped parcel whose zone has an approved flat fee. If three distinct parcels went to the same zone, finance expects three charges at that zone’s rate. A tariff listed for a zone with no shipments produces no charge. Keep every parcel in the reporting population, including parcels without a price. This lets finance distinguish how much it can support from how many items remain unresolved. Confirm with the tariff owner that the same schedule covers both weeks before treating a zone alone as the pricing key.

Q02Which fields can we trust as keys?

The parcel ID identifies a shipment across the full reporting period. The zone identifies a row in the tariff schedule and can repeat freely in the manifests. Read these identifiers as text and inspect missing values before combining the files. The weekly headers must describe the same fields. An ID appearing in both exports requires investigation, even if the zone is identical. The tariff file requires one row per zone and a present, nonnegative fee. Otherwise it is possible to match an identifier while still lacking a usable price.

Q03Where do concatenation and merging each belong?

Concatenation stacks the weekly rows because both files describe the same kind of event. A merge attaches columns by comparing the values of a key. Put the combined parcels on the left and use their zone to find a fee on the right. A left merge keeps a parcel whose zone is unfamiliar. An inner merge keeps only matched records, while an outer merge would also bring in unused tariff zones. Those unused zones may interest the tariff owner, but they do not represent outgoing parcels for this estimate.

Q04How will we detect missing or multiplied shipments?

First count the incoming rows and check parcel identifiers for duplicates. Require the tariff side of the merge to contain unique keys. Compare the joined row count with the intake, then use a match indicator to divide the ledger into priced and unresolved parcels. The two groups must add back to the intake. Divide the priced count by the complete intake to measure coverage. Finally, reconcile the zone subtotals against the supported total and inspect the parcel IDs on the exception list. A tidy-looking subtotal alone cannot verify completeness.

Q05What should finance do when a zone has no tariff?

Give the tariff owner a list with the parcel ID and the zone code exactly as supplied. That person can check whether the warehouse used the wrong code or the approved schedule needs an additional zone. Finance can use the matched subtotal as a provisional estimate while keeping the unresolved parcels visible. Replacing their missing prices with zero would imply an approved free delivery. Borrowing another zone’s fee would make the estimate depend on an undocumented assumption. Once the owner supplies the correction, rerun the whole ledger and reconcile it again.

05

Project resources

parcel_resources.zip

Two weekly manifests and one zone tariff schedule · 3 CSV files

Download resources ↓
parcel_id zone
P0001 Z1
P0002 Z2
P0003 Z3
P0004 Z1
P0005 Z2

Preview from week_1.csv. Both manifests use parcel_id and zone. The tariff schedule uses zone and fee_bdt, the approved charge in whole taka for one parcel.

06

Topic Lesson — Data Joining in python

Explore the topic through interactive visual learning.

TOPIC LESSON
01 / 10
FOUNDATIONS

Two ways to combine tables

Start with what a row represents. In each manifest, one row means one parcel. Adding another week should extend that list. In the tariff schedule, one row means one zone price. Bringing a fee into the manifest should add a column to each parcel. Concatenation handles the first task. A keyed merge handles the second. Together they give finance a shipment ledger it can trace back to the original files.

Two weeks of parcels → one ledger with a fee column
Week 1Week 2ParcelsTariffsLedger
Key takeaway · Identify the meaning of one row before combining tables.
1 / 10 slides explored
07

Build the solution

Complete the missing Python operations and run your analysis.

Reconcile the two-week parcel ledger

Fill each blank with one Python identifier. Use the hint beside a line when you need a clue. The dataset loads automatically when you submit your code.

parcel_close.py0 / 23 filled
01# Load the table analysis library.
02import as pd
03# Read week 1 with identifiers stored as text.
04w1 = pd.("week_1.csv", dtype="string")
05# Read week 2 with identifiers stored as text.
06w2 = pd.("week_2.csv", dtype="string")
07# Load the tariff lookup and preserve the zone key.
08rates = pd.("tariffs.csv", dtype={"zone": "string"})
09# Check that the weekly headers agree in order.
10assert w1.columns.(w2.columns)
11# Stack the two manifests into one parcel ledger.
12parcels = pd.([w1, w2], ignore_index=True)
13# Require an identifier for every parcel.
14assert parcels["parcel_id"].().all()
15# Reject parcel IDs repeated across either week.
16assert parcels["parcel_id"].
17# Require a zone key on both sides of the lookup.
18assert parcels["zone"].notna().() and rates["zone"].notna().all()
19# Check that every listed tariff is present and nonnegative.
20assert rates["fee_bdt"].notna().all() and rates["fee_bdt"].(0).all()
21# Attach one tariff per zone and retain unmatched parcels.
22ledger = parcels.(rates, on="zone", how="left", validate="many_to_one", indicator=True)
23# Reconcile the joined row count with the intake.
24assert (ledger) == len(parcels)
25# Flag parcels whose zone has a tariff.
26matched = ledger["_merge"].("both")
27# Select the rows that finance can price.
28priced = ledger.[matched]
29# Build the exception list with parcel IDs and zones.
30pending = ledger.[~matched, ["parcel_id", "zone"]]
31# Total the supported charges separately for each zone.
32zone_totals = priced.("zone")["fee_bdt"].sum().sort_index()
33# Add the supported parcel fees in BDT.
34subtotal = int(priced["fee_bdt"].())
35# Measure the percentage of all parcels with a rate.
36coverage = 100 * len(priced) / (ledger)
37# Confirm that every incoming parcel has a disposition.
38assert len(priced) + len(pending) == (parcels)
39# Display the parcel reconciliation.
40(f"Parcels {len(ledger)} | Priced {len(priced)} | Pending {len(pending)}")
41# Display the supported subtotal and coverage.
42(f"Supported BDT {subtotal} | Coverage {coverage:.2f}%")
43# Display the priced subtotal for each zone.
44print(zone_totals.())
45# Display the parcel-level handoff for tariff review.
46print(pending.(index=False))
08

End of the lesson

Reflect on your learning experience.

How was your learning experience?

Select a rating

Recommended resource

Explore additional learning resources to deepen your understanding.

Python course topics
UDEMY · COURSE RESOURCE

Data Analytics, Data Science, ML, DL & NLP - All in 1 Course

A Udemy course covering data analytics, data science, machine learning, deep learning, and natural language processing.

View the complete course →