Start a Python data analysis by writing the question in one sentence. Define what each row represents, decide which records belong in the denominator, and check a few cases by hand before summarizing the full dataset. For a library pickup rate, count eligible reservations and divide the number collected on time by that total.
Imagine a library that wants to know whether an evening pickup window helps people collect reserved items. Its export contains one row per reservation. A successful pickup appears as a timestamp, cancellations have a reason, and reservations still open have no final state. The first job is deciding which of those records can answer the question.
Define the unit, the period, and the denominator
A question such as “Did the evening window work?” hides several measurements. Try “Among eligible reservations opened during the first four full weeks in March, what share were collected within seven days?” That names a population, an observation window, and an outcome. Define the corresponding comparison period separately. If you compare users who chose the evening window with those who did not, people’s schedules and preferences can explain a difference. The descriptive comparison alone cannot show what the window caused.
Write down the row unit before picking a tool. A reservation table can describe a pickup rate. A scan-event table may contain three rows for a reservation that was eventually collected once. Counting event rows would change both numerator and denominator. First assemble one outcome for each eligible reservation, using a documented rule for resolving multiple events.
Check input before calculating
Inspect a handful of records from different dates and sources. Verify identifiers, types, timezone assumptions and the spelling of statuses. Keep reservation IDs such as 0042 as text. Leading zeros may be meaningful, and a numeric conversion can cause two distinct IDs to collide. Check how the source represents cancellation, open status and missing timestamps. An empty field can have different meanings in different columns.
Count rows at each boundary. Record raw rows, distinct reservations, invalid rows, ineligible rows and eligible rows. If some rules overlap, choose the order of exclusions or show the overlaps explicitly. A useful reconciliation lets a colleague trace the final 800 reservations back to the export with 1,025 rows. Pay special attention to cases close to the end of the period. If the data was extracted four days later, some reservations have had insufficient time to reach the seven-day outcome.
Calculate the answer in a small, visible step
Suppose validation leaves two cohorts with known outcomes. Include their counts in the result so a reader can distinguish a small sample from a large one. The example uses synthetic numbers.
cohorts = [
("March evening window", 78, 100),
("March daytime window", 56, 80),
]
for label, picked_up, eligible in cohorts:
if not 0 <= picked_up <= eligible:
raise ValueError(f"Invalid counts for {label}")
rate = f"{picked_up / eligible:.1%}" if eligible else "unavailable"
print(f"{label}: {picked_up} of {eligible} ({rate})")
The printed rates are 78.0% and 70.0%, a difference of eight percentage points. The combined rate is 134 pickups out of 180 eligible reservations, or 74.4%. Averaging the displayed rates gives 74.0% because that calculation weights the two cohorts equally. Use the combined counts when the question is about individual reservations.
Look for a different answer inside the totals
A single cohort rate can conceal an important imbalance. Suppose evening reservations mostly come from a branch with longer hours, while daytime reservations mostly come from a branch with fewer pickup days. The branch mix may explain the difference. Show counts by branch or reservation type if those are plausible influences on pickup. Decide which slices matter before reading too much into every pattern.
Small groups warrant care. A category with two reservations and two pickups will report 100%. Someone seeing only the ranked percentages might mistake it for the most dependable program. Set a minimum coverage rule when ranking groups, show the small denominators, or explain why the comparison is preliminary. Report the underlying counts even if you omit a ranking. If data is sensitive, verify what may be shared at that level.
Try the same calculation for a second defensible definition, such as pickup within five days. A changed conclusion can be useful because it shows that the choice of threshold matters. Keep one primary definition and label the second as a sensitivity check. Changing definitions until one makes a preferred group look better undermines the value of the analysis.
Choose a tool that suits the question
The Python standard library can read a few files, group counts, compute medians and write a CSV report. If you repeatedly filter tables, join them to reference data, or reshape them, pandas can make the operations easier to inspect. SQLite is useful when the same local data supports many queries. A chart library comes in after you have established what each statistic represents. Choose a workflow that the next reader can run and understand, including any dependencies it requires.
A notebook is useful when you want code, notes and intermediate tables together. Restart the kernel and run the notebook from top to bottom before sharing it. A script works well when the analysis repeats on a schedule or accepts file paths as inputs. In either format, keep original records separate from cleaned data and report files. Give generated files predictable names and include enough context to tell an old output from a new one.
Verify and deliver the result
Hand-check three records. Include one collected reservation, one excluded reservation, and one near the seven-day cutoff. Compare your manual classification with what the program produces. Test a group with no eligible records and a repeated identifier. Both situations should have defined behavior. Run the analysis on different input orderings if the result is supposed to ignore order.
State what you observed in plain language. Of the eligible reservations in the sample, 78 of 100 evening reservations and 56 of 80 daytime reservations were collected within seven days. People chose their pickup windows, so the difference could also reflect who used each window. Save the source reference, cleaning rules and the script or notebook used for the calculation. If someone else needs to act on the comparison, use this data analysis report guide to present the counts, coverage and limitations together.