0 / 8 activities
APPLIED DATA ANALYTICS

Missing value in Python — 10 Essential Steps to Better Data

Find a Missing value in Python, build a SimpleImputer workflow for delivery records, and learn how to keep estimated values visible in a planning dashboard.

Data AnalyticsPython · pandasSimpleImputer
Start the project →
Missing value in Python workflow showing delivery blanks, historical fill rules, and audited estimates
01

The real-world scenario

Read the business brief before touching the code.

BUSINESS BRIEF

Harborline Parcel is a fictional courier that handles deliveries across Central, North, and Riverside. Its planning team is preparing a weekly dashboard when the latest export arrives with gaps. Some records have no delivery duration, some have no parcel weight, and some have no service type. The dashboard expects those fields to be populated. If the team simply drops incomplete rows, it may hide how much work each zone handled. If it treats blanks as zeros, an incomplete record can look like an instant delivery or a weightless parcel.

The team has an export of 300 deliveries in reporting order. The first 240 belong to the historical reference period, and the last 60 form the current batch. Each row has a delivery ID and a zone. The main measurements are minutes and kilograms, and the service type records the booked tier. Earlier records contain gaps as well, but they give the team observed examples it can use as a starting point. Managers also want to see where current duration gaps tend to occur so they can investigate the capture process.

Deliver a complete working copy for the planning dashboard and a short data-quality report. Keep the original log available for audit, preserve which duration entries were missing, and recommend the first zone to investigate. Make the limits of estimated values clear to anyone using the dashboard.

02

Your role

YOUR ASSIGNMENT

Operations Data Analyst

You are the Operations Data Analyst supporting Harborline’s reporting team. Your first responsibility is to separate missing data from unusual but valid values. You will check each field, measure how common its gaps are in the current batch, and find out whether duration gaps are concentrated in one zone. Then you will choose an approach that fits both numeric measurements and service labels.

Prepare reproducible Python code that learns replacement values from the historical period and applies them to the current batch. Keep IDs and row order intact, and preserve an indicator that tells readers which durations were filled. Your handover should include a before-and-after check, the values used to fill gaps, and a recommendation for improving capture.

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.

Q01Which business outcome should the cleaned table support?

The team needs a planning view that includes every delivery and preserves a link to the original log. Use the current batch as the unit of reporting, and count missing values separately for duration, weight, and service tier. The business question about capture is narrower: which zone contributes the most missing duration records this week? Treat duration quality as its own issue because delivery time may inform staffing. Keep any imputed duration visibly flagged so that a downstream report can distinguish measured values from estimates when evaluating a delivery promise.

Q02What does a blank mean in each field?

A blank duration means the export lacks a recorded number of minutes. A blank weight means the parcel measurement is absent, and a blank service tier means the booked category was not recorded in the export. Check the data contract for other missing markers such as whitespace or sentinel values before using this procedure in production. pandas normally reads the empty fields here as missing. Treat an unusual measured value as a separate issue that requires domain checks. Start by checking unique delivery IDs and by keeping the historical and current sections in their original reporting order.

Q03Why choose two different imputation strategies?

Choose a method that matches the type of each column. Duration and weight are numeric, so their historical medians provide simple replacement values. A median is less influenced than a mean by a few extreme observations, such as deliveries delayed for an extended period. Service type is text, so the most frequent category gives the baseline replacement. Use two SimpleImputer objects because each has one strategy setting. Fit both using only the historical portion, then transform the current portion. Review unusual historical distributions separately because a single typical value can hide important differences among routes or service tiers.

Q04How do we know the repair did what we intended?

Compare the current counts before and after transformation. Divide each before count by the current batch size and multiply by 100 to get a field-level missing percentage. A record may contain multiple gaps, so adding the three counts measures missing cells. Verify that the three after counts are zero, the row order and IDs are preserved, the observed values are unchanged, and the duration flag matches the original mask. These checks validate the transformation. To estimate the quality of individual replacements, a separate backtest could hide observed historical values or compare fills with later recovered records.

Q05How should operations act on the duration flags?

Group the original duration flag by zone and count the true values. This shows where the missing records came from before any imputation made the table look complete. Direct the first investigation to the zone with the largest count because that is where a review can cover the most flagged cases immediately. In a production report, check the percentage alongside the count because large zones may naturally contribute more gaps. Ask whether capture failures follow a driver workflow, device, or handoff step. Treat a concentration as a starting point for investigation, and keep estimated durations separate from contractual performance records.

05

Project resources

delivery_quality.csv

CSV · 300 deliveries · 5 fields · historical and current batches

Download dataset ↓
First five current-batch records. An em dash marks an empty field.
delivery_idzoneduration_minweight_kgservice_type
D0241Central516.7Standard
D0242North507.6—
D0243Riverside420.5Express
D0244Central263.9Express
D0245North434.8Standard

delivery_id identifies the delivery. zone marks its service area. duration_min is the recorded delivery time in minutes. weight_kg is the measured parcel weight in kilograms. service_type is the booked tier. The first 240 rows form the historical batch and the last 60 form the current batch.

06

Topic Lesson — Missing value in Python

Explore the topic through interactive visual learning.

TOPIC LESSON
01 / 10
FOUNDATIONS

What a missing value represents

A missing value in Python marks a cell for which we lack a usable observation. pandas can build a true-or-false mask from a table, and SimpleImputer can use a reference table to learn a replacement for each selected column. The resulting working table has estimates where the measurements were absent. Preserve the mask for any field whose original status matters. The small example shows how a reported duration differs from an estimated one.

isna() → True for missing cells
Observed and estimated. Observed • 31 min. Missing • no reading. Filled • 38 minWORKED EXAMPLEObserved and estimatedObserved • 31 minMissing • no readingFilled • 38 min
Key takeaway: An imputed value is an estimate. Preserve its original missing status.
1 / 10 slides explored
07

Build the solution

Complete the missing Python operations and run your analysis.

Audit and repair the current delivery batch

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.

delivery_repair.py0 / 25 filled
# Import pandas to read and inspect the delivery records.
import as pd
# Import the scikit-learn tool that learns replacement values.
from sklearn.impute import
# Load the delivery quality CSV into a DataFrame.
log = pd.("delivery_quality.csv")
# Check that each delivery ID appears only once.
assert log["delivery_id"]., "Duplicate delivery ID"
# Use the first 240 rows as historical data for learning replacements.
history = log.[:240].copy()
# Reserve the remaining rows as the current deliveries to repair.
current = log.iloc[240:].()
# Group duration and weight as numeric fields and service type as a category.
numeric, categorical = ["duration_min", "weight_kg"], [""]
# Combine the field lists for the missing-value audit.
fields = numeric +
# Mark each missing cell in the selected current fields.
missing = current[fields].()
# Count the missing cells in each field before filling them.
before = missing.()
# Express each missing count as a percentage of current deliveries.
rates = before.(len(current)).mul(100)
# Count missing durations in each delivery zone.
by_zone = missing.groupby(current["zone"])[numeric[0]].()
# Choose the median as the replacement for each numeric field.
num = SimpleImputer(strategy="")
# Choose the most frequent historical category for each categorical field.
cat = SimpleImputer(strategy="")
# Learn each numeric column’s median from historical deliveries.
num.(history[numeric])
# Learn the most frequent service type from historical deliveries.
cat.fit(history[])
# Copy current deliveries so the original observations remain available.
clean = current.()
# Fill missing durations and weights with their historical medians.
clean[numeric] = num.(current[numeric])
# Fill missing service types with the historical most frequent value.
clean[categorical] = cat.(current[categorical])
# Flag deliveries whose duration was originally missing.
clean["duration_imputed"] = missing[[0]]
# Count how many missing cells remain in each repaired field.
after = clean[fields].isna().()
# Verify that all target cells are filled and row indices are preserved.
assert after.() == 0 and clean.index.equals(current.index), "Check repair"
# Display original missing counts and rates rounded to two decimal places.
print("Current missing:", before.to_dict(), "| %:", rates.(2).to_dict())
# Display the replacement values learned from historical data.
print("Historical fills:", num..tolist(), cat.statistics_.tolist())
# Report remaining missing counts and originally missing durations by zone.
print("Remaining:", after.to_dict(), "| Duration flags by zone:", by_zone.())
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 →