Data Cleaning Exercises

Module 6 · Numbers and money · 6 min

Totals per currency

You'll be able to: Aggregate amounts per currency and never add different currencies together.

Before this: Exact decimals for money

The idea

A sum of USD and EUR has no meaning. Group by currency and report one total per currency, with counts.

If a single figure is required, convert in a separate, documented step with a named rate source, date and direction.

Keep amounts exact (DECIMAL) through the aggregation.

Worked example

Input: (10.00 USD), (5.00 EUR), (2.50 USD)

Visual
Add step → Group and total → by currency → sum(amount), count
SQL (DuckDB)
SELECT currency, SUM(amount), COUNT(*) FROM payments GROUP BY currency
pandas
df.groupby("currency")["amount"].agg(["sum", "count"])

Result: USD 12.50 (2), EUR 5.00 (1)

Common mistakes

  • Summing across currencies.
  • Floats in totals.
  • Undocumented conversion rates.

Check yourself

What must a conversion step document?

The rate source, the rate date and the direction of conversion.

Practice it

Sum amounts by currency, without converting.

Next: Sum amounts by currency, without converting