0 / 8 activities
APPLIED DATA ANALYTICS

Data cleaning in python — 10 Essential Steps to Better Data

Practice Data cleaning in python on warehouse receipts. Find inconsistent entries, assign reliable data types, and remove scanner repeats before releasing the monthly intake total.

Data AnalyticsPython · pandasData validation
Start the project →
Data cleaning in python workflow showing raw receipt entries, a validation check and released units
01

The real-world scenario

Read the business brief before touching the code.

BUSINESS BRIEF

At Linden Parts, a fictional spare-parts distributor, the receiving supervisor has one afternoon to close the April intake report. Three docks send their scanner exports to the same spreadsheet. When a connection drops, a clerk can resend a receipt. When a scanner is unavailable, the clerk types the entry by hand. The supervisor has spotted a quantity marked “pending” and two spellings of North. A straight sum could count the same arrival twice or leave a real arrival out.

The export contains a receipt number, receiving date, dock and unit count. Each receipt represents one intake event. A receipt number is an identifier, including its leading zeros. The approved docks are East, North and South. A completed intake must have a real calendar date and a positive whole number of units. The supervisor can confirm spelling differences caused by spaces and capital letters. Only the receiving team can confirm an unfamiliar location or an unreadable count.

Your handover must answer one question. How many units can the supervisor release into the April report today? Give a subtotal for each dock, keep the original entries that need someone’s attention, and show where every input row went. A colleague should be able to apply the same rules when the next export arrives.

02

Your role

YOUR ASSIGNMENT

Operations Data Analyst

You are the operations data analyst assigned to receiving. Your first task is to learn what a row represents. Ask the supervisor which differences are only formatting and which differences could mean that two people reported different events. Inspect the file before changing it. A column that looks numerical on screen may still contain text, and an identifier made entirely of digits can still need its leading zeros.

Deliver a working Python reconciliation that another analyst can rerun. Produce one typed table of usable receipts, a separate set of original rows for follow-up, and a count of repeated submissions. Explain how you checked the released total and what evidence the receiving team needs before it can include a held receipt.

03

Identify the problem

What is the core reporting problem, and which data preparation method would you use?

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

04

Investigate

Ask the right questions before developing your solution.

Q01What exactly should the April report count?

Count individual pieces from completed intake events. A receipt for eight units contributes eight to its dock’s subtotal even though it occupies only one row. The receipt number identifies the event across scanner retries. Two rows with the same quantity on the same day may describe different arrivals, so the date and quantity alone cannot identify a repeat. Ask receiving to confirm that each receipt number belongs to one event and that the export covers April. Keep the report’s scope explicit so a later reader can tell an intake total from the stock currently on the shelf.

Q02Which fields need special treatment at import?

Read all four columns as text first. For example, receipt 00001 must keep its leading zeros so a supervisor can find the matching source document. Examine the distinct dock labels and their frequencies before grouping anything. A leading space is easy to miss on screen, while a quoted representation of the label makes it visible. Dates arrive as year, month and day. Quantities can include a word even when most entries look like integers. Keep an untouched copy so a failed conversion can always be traced back to what the clerk supplied.

Q03Which inconsistencies can we fix automatically?

Spaces around a dock name and differences in capitalisation have an agreed interpretation. Trim the spaces and standardise case before comparing the label with the three approved names. A value such as Annex is different. It might describe a temporary unloading point, but the export gives no approved mapping. Hold that row for review. Apply the same reasoning to quantities. A numeric parser can read 2.5, yet the business accepts only whole pieces. Check both the technical conversion and the operating rule before allowing a value into the report.

Q04How can we check that the cleanup kept the right receipts?

Start with a count reconciliation. Every source row must end in exactly one group: held for review, removed as a repeat, or released. The three counts must add up to the input count. Then check that receipt IDs are unique in the released table and that the units column has an integer type. A count check by itself cannot detect two different receipts accidentally exchanged between groups. Inspect the held IDs and compare the released records with the source. Finally, add the three dock subtotals and check that they give the released unit total.

Q05What should the supervisor do with a held receipt?

Send its original ID and fields to the receiving clerk who can check the delivery note. If the quantity says pending, obtain the counted pieces. If a date is impossible, request the dated source document. For an unfamiliar dock, confirm the authorised location before changing its label. Keep the held receipt outside the current released total until there is evidence for the correction. When a correction arrives, rerun the same checks on the updated source and compare the new release with the previous one. Adding corrected quantities directly to a report could count a resubmitted receipt twice.

05

Project resources

receiving_log.csv

CSV · 300 receiving submissions · 4 fields

Download dataset ↓
First five source rows in their original order.
receipt_idreceived_ondockunits
000012026-04-01North8
000022026-04-02South15
000032026-04-03Eastpending
000042026-04-04North29
000052026-04-05South36

receipt_id identifies one intake event. received_on is its calendar date. dock is the unloading location. units counts individual pieces. Each row represents one submitted receipt, including possible retries.

06

Topic Lesson — Data cleaning in python

Explore the topic through interactive visual learning.

TOPIC LESSON
01 / 10
FOUNDATIONS

A value has a spelling and a meaning

A CSV file carries characters. The characters 00001 name a receipt, while the characters 8 measure pieces. Treating both fields as numbers would destroy part of the identifier. Data cleaning in python turns the raw entries into a table whose types and values match the receiving rules. The output also includes the rows that could not be interpreted safely, so someone can investigate them.

00001 → identifier     8 → quantity
FIELD MEANINGSReceipt number00001textCounted pieces8integerReceiving day2026-04-01date
Key takeaway: Choose a type by asking what the field means.
1 / 10 slides explored
07

Build the solution

Complete the missing Python operations and run your analysis.

Reconcile the April receiving log

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.

receiving_audit.py0 / 25 filled
# Import pandas for reading and cleaning the receiving log.
import as pd
# Read every CSV field as text to preserve receipt IDs and original entries.
raw = pd.("receiving_log.csv", dtype="string", keep_default_na=False)
# Record each source column’s data type before making changes.
raw_types = raw..astype(str).to_dict()
# Count the original dock labels to spot spelling and spacing differences.
dock_counts = raw["dock"].().to_dict()
# Make a working copy so held rows can retain their original values.
work = raw.()
# Trim spaces and standardize capitalization in the dock labels.
work["dock"] = work["dock"].str.strip().str.()
# Parse receiving dates and mark unparseable entries as missing.
work["received_on"] = pd.(work["received_on"], format="%Y-%m-%d", errors="coerce")
# Convert units to numbers and mark nonnumeric entries as missing.
qty = pd.(work["units"], errors="coerce")
# Accept only positive whole quantities, treating missing values as invalid.
valid_units = (qty.gt(0) & qty.mod(1).(0)).fillna(False)
# Check each dock against the three approved locations.
valid_dock = work["dock"].(["East", "North", "South"])
# Require a valid quantity, an approved dock, and a parsed date.
valid = valid_units & valid_dock & work["received_on"].()
# Keep the original entries that failed validation for follow-up.
held = raw.[~valid].copy()
# Select the standardized rows that passed every check.
accepted = work.loc[valid].()
# Store accepted quantities as nullable integers.
accepted["units"] = qty.loc[valid].("Int64")
# Store the accepted dock labels as categories.
accepted["dock"] = accepted["dock"].("category")
# Flag every exact repeat after its first occurrence.
repeat = accepted.(keep="first")
# Keep one copy of each distinct accepted row.
clean = accepted.().copy()
# Check that no receipt ID remains on two distinct released rows.
assert clean["receipt_id"]., "Conflicting receipt IDs require review"
# Verify that held rows, repeats, and released rows account for every input row.
assert len(raw) == len(held) + int(repeat.()) + len(clean)
# Sum released units for each dock present in the cleaned data.
units_by_dock = clean.groupby("dock", observed=True)["units"].()
# Display the original column types.
print("Source types:", )
# Display the frequency of each original dock label.
print("Raw dock labels:", )
# Display the column types after cleaning.
print("Clean types:", clean..astype(str).to_dict())
# Report how many rows entered each stage of reconciliation.
print("Input / held / repeats / released:", len(raw), len(held), int(repeat.sum()), len())
# Report each dock’s released units and the combined total.
print("Units by dock:", units_by_dock.to_dict(), "| Total:", int(units_by_dock.()))
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.

Data preparation illustration showing the inspection, cleaning, and analysis workflow
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 →