Stepthrough Start free

Python: Clean a Messy Invoice Export Before You Total It

Practice it step by step

Start the free practice

Take the free module: why it matters, practice and a quick check →

You do every step yourself in a practice copy of Google Colab. It checks your work as you go, and “Do it for me” finishes any step you get stuck on. Free, about 12 minutes, and nothing touches your real accounts. Open full screen

Free · Live nowPythonGoogle Colab~12 min10 stepsBeginner

Updated . Built against the tool’s current screens and checked step by step. How we check this lesson

A beginner Python walkthrough in the free Google Colab: fix stray spaces and capitals, turn "1,250" text into numbers and remove a duplicate invoice before totalling, typing every line yourself.

At a glance

QuestionAnswer
What you buildA beginner Python walkthrough in the free Google Colab: fix stray spaces and capitals, turn "1,250" text into numbers and remove a duplicate invoice before totalling, typing every line yourself.
ToolsGoogle Colab
TimeAbout 12 minutes, 10 steps in 3 parts
LevelBeginner, no coding needed
CostFree
Ways to learn itPractice it step by step

The 3 parts, in short

  1. The messy export: The client names, The amounts, as text, The invoice numbers, Make the table, and 1 more step.
  2. Clean it: Fix names and amounts, Drop the duplicate, Run it.
  3. Total it: Total each client, Run it.

Start here first: Python: Total a Sales Export by Customer in Google Colab (module 1 of Python)

A Colab notebook named Stepthrough tests - Invoice cleanup: pandas loaded and a new empty cell
A Colab notebook named Stepthrough tests - Invoice cleanup: pandas loaded and a new empty cell

What you'll build

The invoice export at Lakeside Office Supply (made up) is messy: "maple dental " with a trailing space, "COBALT LEGAL" in capitals, amounts stored as text like "1,250", and one invoice exported twice. Total it as it is and Cobalt Legal is counted twice, under two spellings. In this lesson you clean it in Google Colab with three pandas lines (tidy the names, turn the amounts into numbers, drop the duplicate) and then total each client. You type every line yourself.

Three clients, three invoices, $2,750: Maple Dental $1,250, Cobalt Legal $860 and Harbor Accounting $640. Without the clean-up, Cobalt Legal would have shown up twice and been double-counted. Keep the three cleaning lines and run them on every new export. Do it in Colab yourself: the lesson page has the checklist.

  • Tools: Google Colab
  • Time: about 12 minutes, 10 steps in 3 chapters
  • Level: beginner, no coding needed
  • Price: free

Practice first, then build it for real

Practice copy built from real Google Colab screens (captured 24 October 2026). Every line of Python in it was typed and run there. Nothing here touches your Google account. Our account shows a PRO badge; everything in the lesson works the same in free Colab. The shop, its customers and its numbers are made up, and the account picture is blurred. To build it for real you need your own Google Colab account, and some services charge once you use them for real work, so check each tool's current pricing.

Try it yourself, free

Reading the steps is a start. Doing them is how it sticks. The interactive module walks you through every click in a practice copy of Google Colab, checks each step, and never touches your real accounts.

Start “Python: Clean a Messy Invoice Export Before You Total It”

Step by step: Python: Clean a Messy Invoice Export Before You Total It

All 10 steps of the interactive module, in order. In the module you watch each one, then do it yourself in a practice copy that checks your work.

1. The messy export

  1. The client names. Start a new Colab notebook and run import pandas as pd. In the new cell, type the client names exactly as the export has them, mess included: a trailing space, a name in capitals, a leading space.

    In a new notebook with pandas loaded, type the client names exactly as the export has them, mess and all.

  2. The amounts, as text. Press Enter. The export stores amounts as text with commas, so type them in quotes.

    The amounts came out as text with commas, so they go in quotes.

  3. The invoice numbers. And the invoice numbers. Invoice 102 is in the export twice.

    And the invoice numbers. Invoice one oh two is in there twice.

  4. Make the table. Press Shift+Enter to run the cell. In the new cell, put it all in one table and show it.

    Run it with Shift Enter, then put everything in one table and show it.

  5. Run it. Press Shift+Enter: Colab runs the cell and opens a new empty cell below. (In the practice, click the run button ▶ at the left of the cell.)

    Run it.

2. Clean it

  1. Fix names and amounts. There it is: the same client spelled two ways and "1,250" stored as text. Two lines fix that. strip() removes spaces at the ends and title() gives every name the same capitals; replace removes the commas and astype(int) turns the text into whole numbers.

    Two lines fix the mess. The first tidies the names. The second removes the commas and turns the amounts into numbers.

  2. Drop the duplicate. Now that both Cobalt Legal rows are spelled the same, they are exact copies. Remove the copy and show the result.

    Now the two Cobalt Legal rows match exactly. Drop the duplicate, and show the table.

  3. Run it. Press Shift+Enter: Colab runs the cell and opens a new empty cell below. (In the practice, click the run button ▶ at the left of the cell.)

    Run it.

3. Total it

  1. Total each client. Three clean rows: one per invoice, amounts as numbers. Now the totals are safe.

    Three clean rows. Now the totals are safe.

  2. Run it. Press Shift+Enter: Colab runs the cell and opens a new empty cell below. (In the practice, click the run button ▶ at the left of the cell.)

    Run it.

Screenshots

Start this module free

More in Python

All 3 modules in Python

Free cheat sheet

Print it or save the PDF: the key steps and checks from this lesson on one page, free.

All free printable cheat sheets

Plain-English definitions, each with an example from a free lesson.

The full AI glossary

Browse related tutorials