Period 12 · Creating Reporting Variables
[video] Lecture video — Period 12: Creating Reporting Variables — /api/lesson-media/videos/4d3653ff-a3ca-4f63-bf8e-bb93c553e599-1794847915226-91c0a8568ac849ca.mp4
[markdown] content available only on the platform
[markdown] content available only on the platform
Flashcards · Creating Reporting Variables
Revenue after discount — Quantity times unit price times (1 - discount rate), excluding tax, shipping and returns unless stated.
2 x 100,000 x 0.9 = 180,000 dong
Input validation — Checking that required values are present and inside their allowed ranges before calculating.
`assert sales["discount_rate"].between(0, 1).all()`
dt.to_period() — Converts dates to period labels such as month or quarter, keeping the year.
`sales["date"].dt.to_period("Q")` gives 2025Q1.
pd.cut() — Assigns numeric values to labelled intervals defined by bin edges.
`pd.cut(revenue, bins=[0, 180_000, 220_000, np.inf], labels=[...])`
right=False — Makes each interval include its left boundary and exclude its right boundary.
Exactly 180,000 falls in Medium, not Low.
Value band — A category grouping transactions by amount, based on agreed thresholds.
Low, Medium, High revenue bands
reset_index() — Turns the group labels in the index back into an ordinary column.
`summary = sales.groupby("region").agg(...).reset_index()`
np.isclose() — Compares numbers within a tolerance, useful for floating-point totals.
`np.isclose(a, b, rtol=0, atol=0.5)`
Overall mean — Total revenue divided by total transactions, not the average of group means.
770,000 / 4 = 192,500 dong
[pdf] Lecture slides — Period 12 (PDF) — /api/lesson-media/pdfs/4d3653ff-a3ca-4f63-bf8e-bb93c553e599-1794873728650-cc1714214cb38bd5.pdf
