Data Cleaning Exercises

Exercise · beginner · 10 min

Flag large transactions, keep refunds

Mark sales above a review threshold instead of deleting them, and keep negative refunds as valid rows.

The rules

These rules decide what a correct result is. Your answer is checked on this dataset and on hidden datasets that follow the same rules.

Input
  transactions(id, type, amount) — text. id is unique. type is sale or refund.
  amount is always valid: optional "-", digits, optionally "." and 1–2 digits. Refunds are negative.

Rules
  amount: convert to an exact decimal with 2 places (12.5 means 12.50).
  needs_review: true when amount is greater than 5000.00, otherwise false.
  Keep every row. Large values are flagged, never removed or capped.

Output (row order does not matter)
  clean(id text, type text, amount decimal(12,2), needs_review bool)

The data

transactions · 9 rows

idtypeamount
twnh2sale128.99
tthzjsale3529
tkv8bsale8988.5
two43sale280.05
tgsijsale11052.01
t958jrefund-3290.10
tbd8esale2294.10
tu51rsale1710.05
thfhmsale5000.00

What you practise

  • flags
  • decimals
  • outliers

Your answer is also checked on hidden datasets generated from the same rules.

Download this dataset (CSV) with its data dictionary

Sign in to bookmark this and keep private notes.