Use pandas to answer eight questions about a fictional campus café. These are invented practice records, not real orders or business evidence. Every task starts from fresh data and can be attempted independently. Read the three questions, write your code, and explain your choices in plain words. Use a fresh helper table at the start of each task. Suggested working time is 60–90 minutes, followed by a short oral check. The 40-point score gives evidence of these skills; it does not guarantee mastery of pandas.
Eight tasks, 40 points. Code checks cover programmed requirements; review written explanations with the rubric. Worked answers are available for self-study, so this is not a secure examination system.
Python loads on your first run. Each task starts with fresh café data.
A01 · Independent task
Build the table from a dictionary
Create a dictionary named order_data with four keys. Use Order_ID = ["P001", "P002", "P003"], Item = ["Tea", "Coffee", "Sandwich"], Quantity = [2, 1, 3], and Unit_Price = [5, 10, 15]. Convert it to a DataFrame named result. Print the table, its shape, and the total quantity. Explain what one row represents.
Starter code
# Build the dictionary here, then create the DataFrame.
order_data = {}
Watch for this. A code check covers programmed requirements. The explanation and rubric still need review.
Your turn
Create a dictionary named order_data with four keys. Use Order_ID = ["P001", "P002", "P003"], Item = ["Tea", "Coffee", "Sandwich"], Quantity = [2, 1, 3], and Unit_Price = [5, 10, 15]. Convert it to a DataFrame named result. Print the table, its shape, and the total quantity. Explain what one row represents.
For the code check, keep these result variable names: order_data, result. Different valid approaches are welcome.
Show a hint
Inspect the input columns, decide what one row represents, and state the result you expect before coding.
The dictionary maps column names to equal-length lists. Each row is one fictional order with one item type. The table has three rows, four columns, and six units ordered. Columns must line up by list position.
Compare your explanations
Read. Review your explanation using the rubric and worked solution.
Predict. Review your explanation using the rubric and worked solution.
Explain. Review your explanation using the rubric and worked solution.
One quick check
What should you do after a code check passes?
What you should be able to explain. I can explain my choices and apply the operation to unfamiliar café data.
A02 · Independent task
Inspect, select, filter, and sort
Start with cafe_orders(). Print its shape and column types. Select RAK orders with Quantity at least 2. Show only Order_ID, Item, and Quantity. Sort by Quantity descending, then Order_ID ascending to resolve ties. Store this table in result and print its first two rows using iloc.
Starter code
df = cafe_orders()
# Inspect the table, build the mask, then select and sort.
Watch for this. A code check covers programmed requirements. The explanation and rubric still need review.
Your turn
Start with cafe_orders(). Print its shape and column types. Select RAK orders with Quantity at least 2. Show only Order_ID, Item, and Quantity. Sort by Quantity descending, then Order_ID ascending to resolve ties. Store this table in result and print its first two rows using iloc.
For the code check, keep these result variable names: df, result. Different valid approaches are welcome.
Show a hint
Inspect the input columns, decide what one row represents, and state the result you expect before coding.
The original table has eight rows and six columns. Four RAK orders meet the quantity rule. C007 comes first with four units, followed by C003 with three. C001 precedes C005 because their quantities tie and IDs are sorted ascending.
Compare your explanations
Read. Review your explanation using the rubric and worked solution.
Predict. Review your explanation using the rubric and worked solution.
Explain. Review your explanation using the rubric and worked solution.
One quick check
What should you do after a code check passes?
What you should be able to explain. I can explain my choices and apply the operation to unfamiliar café data.
A03 · Independent task
Clean with an audit trail
Start with raw_cafe_orders(). Each Order_ID should identify one complete order. Remove exact duplicate rows. Strip Item text and use title case. Standardize Campus to RAK or Dubai, and treat blank Campus as Unknown while retaining a Campus_was_missing flag. Preserve original quantity and price in Quantity_raw and Unit_Price_raw, then parse the working columns as numbers. For this exercise, valid revenue requires a known positive whole-number quantity and a known positive unit price. Do not guess replacements. Put valid orders in result and excluded orders with reason flags in audit. Show both tables and explain which values you excluded. A missing campus alone does not exclude an order from this revenue-ready table.
Starter code
df = raw_cafe_orders()
# Clean labels, preserve source values, and build separate validity masks.
# Keep accepted rows in result and excluded rows with reasons in audit.
Watch for this. A code check covers programmed requirements. The explanation and rubric still need review.
Your turn
Start with raw_cafe_orders(). Each Order_ID should identify one complete order. Remove exact duplicate rows. Strip Item text and use title case. Standardize Campus to RAK or Dubai, and treat blank Campus as Unknown while retaining a Campus_was_missing flag. Preserve original quantity and price in Quantity_raw and Unit_Price_raw, then parse the working columns as numbers. For this exercise, valid revenue requires a known positive whole-number quantity and a known positive unit price. Do not guess replacements. Put valid orders in result and excluded orders with reason flags in audit. Show both tables and explain which values you excluded. A missing campus alone does not exclude an order from this revenue-ready table.
For the code check, keep these result variable names: audit, df, result. Different valid approaches are welcome.
Show a hint
Inspect the input columns, decide what one row represents, and state the result you expect before coding.
Nine raw rows become eight after removing one exact duplicate. C003 has an unparseable quantity, C005 lacks a price, and C006 has zero quantity under the stated positive-quantity rule. Five orders remain. Their known revenue would total AED 75. C007 remains because its quantity and price are valid; its unknown campus must stay visible in any campus report. "Unknown" is a label, not a recovered location.
Compare your explanations
Read. Review your explanation using the rubric and worked solution.
Predict. Review your explanation using the rubric and worked solution.
Explain. Review your explanation using the rubric and worked solution.
One quick check
What should you do after a code check passes?
What you should be able to explain. I can explain my choices and apply the operation to unfamiliar café data.
A04 · Independent task
Calculate revenue and summarize by campus
Start again with clean cafe_orders(), not the cleaned subset from Task 3. Add Revenue = Quantity × Unit_Price. Group by Campus and report Orders, Units, and Revenue_AED using readable column names. Keep Campus as an ordinary column. Store the campus summary in result. Check that grouped revenue equals the total before grouping.
Starter code
df = cafe_orders()
# Add Revenue, group with named aggregations, and reconcile totals.
Watch for this. A code check covers programmed requirements. The explanation and rubric still need review.
Your turn
Start again with clean cafe_orders(), not the cleaned subset from Task 3. Add Revenue = Quantity × Unit_Price. Group by Campus and report Orders, Units, and Revenue_AED using readable column names. Keep Campus as an ordinary column. Store the campus summary in result. Check that grouped revenue equals the total before grouping.
For the code check, keep these result variable names: result. Different valid approaches are welcome.
Show a hint
Inspect the input columns, decide what one row represents, and state the result you expect before coding.
RAK has four orders, eleven units, and AED 95 revenue. Dubai has four orders, six units, and AED 60 revenue. Total revenue is AED 155 from seventeen units. These are revenues before considering any costs; they are not profits.
Compare your explanations
Read. Review your explanation using the rubric and worked solution.
Predict. Review your explanation using the rubric and worked solution.
Explain. Review your explanation using the rubric and worked solution.
One quick check
What should you do after a code check passes?
What you should be able to explain. I can explain my choices and apply the operation to unfamiliar café data.
A05 · Independent task
Join tables and account for unmatched rows
Start with fresh cafe_orders() and cafe_menu(). The menu intentionally omits Sandwich and includes Juice, which was not ordered. Perform an outer merge on Item with validate="many_to_one" and indicator=True. Store the merged table in result. Build audit with every row whose indicator is not both. Report the counts of both, left_only, and right_only. Explain why merged row count differs from order count, and identify which rows represent unmatched orders versus unused catalog entries.
Starter code
orders = cafe_orders()
menu = cafe_menu()
# Merge with validation and an indicator, then inspect unmatched rows.
Watch for this. A code check covers programmed requirements. The explanation and rubric still need review.
Your turn
Start with fresh cafe_orders() and cafe_menu(). The menu intentionally omits Sandwich and includes Juice, which was not ordered. Perform an outer merge on Item with validate="many_to_one" and indicator=True. Store the merged table in result. Build audit with every row whose indicator is not both. Report the counts of both, left_only, and right_only. Explain why merged row count differs from order count, and identify which rows represent unmatched orders versus unused catalog entries.
For the code check, keep these result variable names: audit, result. Different valid approaches are welcome.
Show a hint
Inspect the input columns, decide what one row represents, and state the result you expect before coding.
Six order rows match the catalog. Two Sandwich orders are left_only because the catalog lacks Sandwich. Juice is one right_only catalog row. The outer merge has nine rows but still represents eight orders; the extra catalog-only row is not a transaction. The menu must be unique on Item for many_to_one validation.
Compare your explanations
Read. Review your explanation using the rubric and worked solution.
Predict. Review your explanation using the rubric and worked solution.
Explain. Review your explanation using the rubric and worked solution.
One quick check
What should you do after a code check passes?
What you should be able to explain. I can explain my choices and apply the operation to unfamiliar café data.
A06 · Independent task
Reshape without losing the total
Start with cafe_orders() and calculate Revenue. Create a Campus-by-Item revenue table using pivot_table with sum as the aggregation and 0 for empty combinations. Store it in result. Convert that wide result back to long form in tidy with columns Campus, Item, Revenue_AED. Confirm that the revenue total in tidy equals the original order-level total. Explain why ordinary pivot is unsuitable for these repeated Campus-Item combinations.
Starter code
df = cafe_orders()
# Create the wide table, then melt it into tidy long form.
Watch for this. A code check covers programmed requirements. The explanation and rubric still need review.
Your turn
Start with cafe_orders() and calculate Revenue. Create a Campus-by-Item revenue table using pivot_table with sum as the aggregation and 0 for empty combinations. Store it in result. Convert that wide result back to long form in tidy with columns Campus, Item, Revenue_AED. Confirm that the revenue total in tidy equals the original order-level total. Explain why ordinary pivot is unsuitable for these repeated Campus-Item combinations.
For the code check, keep these result variable names: result, tidy. Different valid approaches are welcome.
Show a hint
Inspect the input columns, decide what one row represents, and state the result you expect before coding.
The wide table has two campus rows and three item columns. RAK totals are Coffee 20, Sandwich 45, Tea 30; Dubai totals are Coffee 40, Sandwich 15, Tea 5. Melting yields six Campus-Item rows with the same AED 155 total. Ordinary pivot cannot aggregate repeated Campus-Item keys. Filling absent combinations with zero is appropriate here only under the exercise assumption that the provided order list is complete.
Compare your explanations
Read. Review your explanation using the rubric and worked solution.
Predict. Review your explanation using the rubric and worked solution.
Explain. Review your explanation using the rubric and worked solution.
One quick check
What should you do after a code check passes?
What you should be able to explain. I can explain my choices and apply the operation to unfamiliar café data.
A07 · Independent task
Parse timestamps and summarize each day
Start with cafe_orders(). Parse Ordered_At using the explicit year-month-day hour:minute format. Calculate Revenue. Build daily totals for Orders and Revenue_AED in chronological order, storing the date-indexed table in result. Identify every day tied for the highest revenue in best_days. All timestamps represent the same local time zone. Explain why a comparison ending at "2026-10-04" midnight could miss October 4 orders later in the day.
Starter code
df = cafe_orders()
# Parse timestamps, resample by day, and preserve all maximum ties.
Watch for this. A code check covers programmed requirements. The explanation and rubric still need review.
Your turn
Start with cafe_orders(). Parse Ordered_At using the explicit year-month-day hour:minute format. Calculate Revenue. Build daily totals for Orders and Revenue_AED in chronological order, storing the date-indexed table in result. Identify every day tied for the highest revenue in best_days. All timestamps represent the same local time zone. Explain why a comparison ending at "2026-10-04" midnight could miss October 4 orders later in the day.
For the code check, keep these result variable names: best_days, result. Different valid approaches are welcome.
Show a hint
Inspect the input columns, decide what one row represents, and state the result you expect before coding.
Daily revenue is AED 20, 50, 35, and 50 on October 1 through 4. Each day has two orders. October 2 and October 4 tie for the maximum. A filter for the complete period through October 4 can use timestamps >= October 1 and < October 5, preserving all October 4 times.
Compare your explanations
Read. Review your explanation using the rubric and worked solution.
Predict. Review your explanation using the rubric and worked solution.
Explain. Review your explanation using the rubric and worked solution.
One quick check
What should you do after a code check passes?
What you should be able to explain. I can explain my choices and apply the operation to unfamiliar café data.
A08 · Independent task
Make a readable chart and export the result
Start with cafe_orders(), calculate Revenue, and build a two-row campus summary named result with Campus and Revenue_AED columns. Create a bar chart with a descriptive title, a campus axis label, a revenue axis label including AED, and a zero baseline. Save the chart as cafe_revenue_by_campus.png in OUTPUT_DIR. Export the summary as cafe_revenue_by_campus.csv in OUTPUT_DIR without an extra index column. Read the CSV back and check that it matches result. State one supported comparison and one claim the data cannot support.
Starter code
df = cafe_orders()
# Build the summary, create the chart, and export only to OUTPUT_DIR.
# Write your interpretation in the answer space, not as a fabricated business conclusion.
Watch for this. A code check covers programmed requirements. The explanation and rubric still need review.
Your turn
Start with cafe_orders(), calculate Revenue, and build a two-row campus summary named result with Campus and Revenue_AED columns. Create a bar chart with a descriptive title, a campus axis label, a revenue axis label including AED, and a zero baseline. Save the chart as cafe_revenue_by_campus.png in OUTPUT_DIR. Export the summary as cafe_revenue_by_campus.csv in OUTPUT_DIR without an extra index column. Read the CSV back and check that it matches result. State one supported comparison and one claim the data cannot support.
For the code check, keep these result variable names: ax, csv_path, plot_path, result, round_trip. Different valid approaches are welcome.
Show a hint
Inspect the input columns, decide what one row represents, and state the result you expect before coding.
Show one worked solution
df = cafe_orders()
df["Revenue"] = df["Quantity"] * df["Unit_Price"]
result = df.groupby("Campus", as_index=False).agg(Revenue_AED=("Revenue", "sum"))
fig, ax = plt.subplots(figsize=(6, 4))
result.plot.bar(x="Campus", y="Revenue_AED", ax=ax, legend=False, color="#286b69", rot=0)
ax.set_title("Fictional café revenue by campus")
ax.set_xlabel("Campus")
ax.set_ylabel("Revenue (AED)")
ax.set_ylim(bottom=0)
fig.tight_layout()
csv_path = OUTPUT_DIR / "cafe_revenue_by_campus.csv"
plot_path = OUTPUT_DIR / "cafe_revenue_by_campus.png"
result.to_csv(csv_path, index=False)
fig.savefig(plot_path, dpi=160)
round_trip = pd.read_csv(csv_path)
pd.testing.assert_frame_equal(round_trip, result)
print(result)
print("RAK revenue exceeds Dubai revenue by AED 35 in these eight fictional orders.")
print("Costs are unavailable, so the table does not establish profit or predict future sales.")
plt.show()
The chart compares AED 60 for Dubai with AED 95 for RAK. RAK exceeds Dubai by AED 35 in the supplied records. CSV export with index=False keeps only the intended two columns. The result describes fictional revenue, not profit, demand, or a forecast. Re-running the task replaces only its two named output files.
Compare your explanations
Read. Review your explanation using the rubric and worked solution.
Predict. Review your explanation using the rubric and worked solution.
Explain. Review your explanation using the rubric and worked solution.
One quick check
What should you do after a code check passes?
What you should be able to explain. I can explain my choices and apply the operation to unfamiliar café data.