0 / 8 activities
APPLIED DATA ANALYTICS

Data sorting & filtering in python — 5 Essential Filters for Better Dispatch Decisions

Use Data sorting & filtering in python to choose three repair visits from a busy service queue. Apply five eligibility tests, resolve priority ties and give dispatch a ranked work order.

Data AnalyticsPython · pandasFiltering & sorting
Start the project →
Data sorting & filtering in python applied to an ordered three-job dispatch queue
01

The real-world scenario

Read the business brief before touching the code.

BUSINESS BRIEF

At Alder Field Service, a fictional repair company, the morning dispatch team has three visits to book for its pump crew. The service desk exports one list for the entire network. Closed jobs sit beside open requests, and a recently edited record can appear at the top even when another customer has waited longer. Yesterday two coordinators picked different jobs from the same file. Today the supervisor wants a list either coordinator can reproduce before calling the customers.

The crew serves North and East. It takes open pump jobs that have waited at least three days and have an estimated visit of one to two hours, including both limits. The asset description identifies pump work, but technicians use different capitalization and occasionally leave the field empty. The export also includes a unique job ID, current status, district and waiting time measured at the morning snapshot.

Which three jobs should the desk call first? Give the oldest eligible jobs priority. If two have waited equally long, choose the shorter visit first. If both values match, use the smaller job ID. Keep the other eligible jobs in order so the desk can fill a cancelled visit without starting again.

02

Your role

YOUR ASSIGNMENT

Dispatch Data Analyst

You are the dispatch data analyst working alongside the morning coordinator. Your first responsibility is to turn the crew’s booking rules into tests that another analyst could repeat. Pay attention to the limits of the visit window, the meaning of a blank equipment description and the difference between a job’s age and its position in the export.

Deliver a ranked three-job handoff with the identifiers, waiting times and estimated hours the coordinator needs for the calls. Keep a reserve list and reconcile its size with the eligible pool. Be ready to explain why two jobs of the same age can receive different priorities and what the coordinator should recheck before confirming a visit.

03

Identify the problem

Which jobs can this crew take, and how should dispatch choose the first three?

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

04

Investigate

Ask the right questions before developing your solution.

Q01What makes a job eligible for one of the three slots?

A slot belongs to one identifiable repair job. Start with jobs marked Open and require a wait of at least three days. The district must be North or East, the duration must fall between one and two hours including the endpoints, and the asset description must contain the word fragment pump in any capitalization. These conditions answer whether the crew can take a job. They do not decide which qualifying job goes first. For example, a five-day pump job in West stays outside this list even when the crew has an unused slot.

Q02Which fields could change a dispatch decision?

Read the six columns as a snapshot. The job ID identifies a request, status indicates whether it is still available, and district identifies the service area. Waiting days and estimated hours use different units, so comparing the wrong column can produce a plausible but misleading list. The asset description is free text. A technician can enter PUMP motor or Pump seal, and some descriptions are blank. Treat a blank as insufficient evidence. Check the IDs before ranking because a repeated job could otherwise occupy two positions in the handoff.

Q03How do filtering and sorting work together?

A filter tests each row and keeps the ones that pass. Sorting changes the sequence of those survivors while carrying every field along with its job ID. Start with the full snapshot and combine all five eligibility conditions. Then sort the eligible table using the supervisor’s rules. For two jobs waiting fourteen days, the shorter visit wins. For equal waits and equal visits, compare job IDs. Take the first three only after sorting. If you take three rows from the export first, a better candidate farther down the file never gets considered.

Q04What would convince us that the queue is correct?

Check examples on both sides of each boundary. A job waiting exactly three days should pass the age test. A one-hour or two-hour visit should pass the duration test, while a half-hour visit should fail it. Look at adjacent rows in the ranked table. Age should never increase as you read downward, and durations should increase or stay equal within each age group. Finally, add the selected and reserve counts and compare the sum with the eligible count. This last check catches a skipped position even when every visible job looks reasonable.

Q05How should the coordinator use the reserve list?

Use the three selected rows as a call order. Before booking, verify the customer is available, the request is still open and the crew can reach the site. If a selected visit falls through, take the first still-eligible job from the reserve list. Keep the reason for the change with the handoff so a colleague can reconstruct it. The dataset has no travel times, appointment windows or live stock information. The ranking supports a fair starting order under the agreed rule. The coordinator still owns the final appointment decision.

05

Project resources

service_jobs.csv

CSV · 300 service jobs · 6 fields

Download dataset ↓
job_id status district wait_days hours asset
J0105 Open South 10 1.0 PUMP motor
J0246 Open North 10 1.0 Pump seal
J0084 Open South 1 0.5 Belt drive
J0296 Closed West 5 0.5
J0163 Open East 13 2.0 Valve body

job_id identifies a repair request. status and district describe availability and coverage. wait_days is the age at export, hours is the estimated visit length, and asset is the technician’s equipment description.

06

Topic Lesson — Data sorting & filtering in python

Explore the topic through interactive visual learning.

TOPIC LESSON
01 / 10
FOUNDATIONS

Choose rows, then choose their order

Think of the service export as a stack of job cards. Filtering removes cards that this crew cannot take. Sorting arranges the remaining cards so the first one has a clear claim on the next slot. Both operations work on whole rows, which keeps each job ID attached to its own age and duration. The result is a smaller table in a meaningful order.

Open cards in age order: C, then A.
ILLUSTRATIVE JOB CARDSA · Open · 4 daysB · Closed · 9 daysC · Open · 6 days
Key takeaway · Eligibility changes membership. Priority changes order.
1 / 10 slides explored
07

Build the solution

Complete the missing Python operations and run your analysis.

Build the morning dispatch queue

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.

dispatch_queue.py0 / 18 filled
01# Load the table analysis library.
import as pd
03# Read the dispatch snapshot from disk.
jobs = pd.("service_jobs.csv")
05# Verify that each job appears only once.
assert jobs["job_id"].
07# Check every job has an identifier.
assert jobs["job_id"].notna().()
09# Identify jobs still open for dispatch.
open_job = jobs["status"].("Open")
11# Identify jobs waiting at least three days.
old_enough = jobs["wait_days"].(3)
13# Select districts served by this crew.
in_area = jobs["district"].(["North", "East"])
15# Check the estimated duration against the booking window.
fits_slot = jobs["hours"].(1, 2, inclusive="both")
17# Find pump descriptions regardless of capitalization.
pump = jobs["asset"].str.("pump", case=False, regex=False, na=False)
19# Require every eligibility condition to pass.
eligible = open_job & old_enough & in_area & fits_slot &
21# Keep the full records for qualifying jobs.
pool = jobs.[eligible]
23# Rank by oldest wait, shortest visit and then job ID.
ranked = pool.(["wait_days", "hours", "job_id"], ascending=[False, True, True])
25# Select the first three ranked jobs.
dispatch = ranked.(3)
27# Set aside qualifying jobs below the cutoff.
reserve = ranked.[3:]
29# Confirm every qualifying job has a place.
assert len(dispatch) + len(reserve) == (pool)
31# Choose the fields dispatch needs to see.
handoff = dispatch.[:, ["job_id", "wait_days", "hours"]]
33# Print the source, eligible and reserve counts.
(f"Snapshot {len(jobs)} | Eligible {len(pool)} | Reserve {len(reserve)}")
35# Display the dispatch table without internal row labels.
print(handoff.(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 →