1
Hatchling0 / 300 XP
0day streak 0stars
Your Python practice
Mock tests Readiness
More
Guest mode · saved on this device.

Pick columns and filter rows

Select one column with orders["amount"]; this returns a Series, a sequence with one value per row. Select spreadsheet fields with a list: orders[["order", "amount"]] returns a two-column table. A comparison such as orders["amount"] >= 100 returns a boolean mask: one True or False per row.

urgent = orders.loc[
    (orders["status"] == "open") & (orders["amount"] >= 100),
    ["order", "amount"]
]

.loc[row_mask, column_list] selects both. Use & for element-by-element AND, and put each comparison in parentheses. Python's and expects one truth value, not a whole column. | means OR; == compares, while = assigns.

Keep boundary cases: >= includes the threshold, > does not. Unless asked to sort, preserve the file's row order.

See it run

import pandas as pd
orders = pd.DataFrame({"order": ["A", "B", "C", "D"], "status": ["paid", "unpaid", "unpaid", "paid"], "amount": [40, 120, 60, 200]})
mask = orders["amount"] >= 100
big = orders[mask]
slim = big[["order", "amount"]]

Filtering is two steps: build a True/False mask, then keep the True rows.

Practice pick columns and filter rows

Exercise 1

The dispatch desk needs unpaid orders worth at least 100 credits. Read dispatch_orders.csv as orders. Build follow_up containing only order and amount for rows where status is "unpaid" AND amount >= 100, in file order.

Exercise 2

A stockroom lead wants a reorder list. Load reorder.csv as stock. Save reorder with item and on_hand only where on_hand < reorder_at. An item exactly at its reorder point does not belong in this particular list. Keep file order.

Exercise 3

For a service-level review, load sla_queue.csv as tickets. Save priority with ticket, team, and age_hours for OPEN tickets at least 24 hours old. Keep the CSV order. Closed tickets are not waiting, however old their record is.

The explanation and tasks are public. Running this lesson requires an account with course access.

Practice

Loading Python…
More
Loading exercise content…
Visualizer Watch your code run line by line

Run your code, then choose Play to follow its execution.

Memory · names → values
Variables appear here as Python creates them.
Output & plots

One-line daily quest