# Python: Clean a Messy Invoice Export Before You Total It

> 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…

Source: https://learn.ynteractive.com/content/python-clean-invoice-export · Updated 2026-10-24 · Free from Stepthrough (https://learn.ynteractive.com)

## Practice it step by step

[Start the free practice](https://learn.ynteractive.com/modules/python-clean-invoice-export)

[Take the free module: why it matters, practice and a quick check →](https://learn.ynteractive.com/courses/python-for-spreadsheet-work/3)

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](https://learn.ynteractive.com/modules/python-clean-invoice-export)

Free · Live now · [Python](https://learn.ynteractive.com/content/course/python) · [Google Colab](https://learn.ynteractive.com/content/tool/google-colab) · ~12 min · 10 steps · Beginner

Updated October 24, 2026. Built against the tool’s current screens and checked step by step. [How we check this lesson](https://learn.ynteractive.com/content/about#how-we-check)

A beginner [Python](https://learn.ynteractive.com/content/glossary/python) walkthrough in the free Google Colab: fix stray spaces and capitals, turn "1,250" text into numbers and remove a [duplicate invoice](https://learn.ynteractive.com/content/glossary/duplicate-invoice) before totalling, typing every line yourself.

## At a glance

| Question | Answer |
| --- | --- |
| What you build | 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. |
| Tools | Google Colab |
| Time | About 12 minutes, 10 steps in 3 parts |
| Level | Beginner, no coding needed |
| Cost | Free |
| Ways to learn it | [Practice it step by step](https://learn.ynteractive.com/modules/python-clean-invoice-export) |

### 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](https://learn.ynteractive.com/content/python-sales-report) (module 1 of Python)

## What you'll build

The [invoice](https://learn.ynteractive.com/content/glossary/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](https://learn.ynteractive.com/content/tool/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”](https://learn.ynteractive.com/modules/python-clean-invoice-export)

## 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

6. **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.
7. **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.
8. **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

9. **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.
10. **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](https://learn.ynteractive.com/modules/python-clean-invoice-export)

- Previous in Python: [Python: Combine Monthly Sales Exports into One Quarter](https://learn.ynteractive.com/content/python-combine-exports)

## More in Python

- [Python: Total a Sales Export by Customer in Google Colab](https://learn.ynteractive.com/content/python-sales-report): A beginner Python walkthrough in the free Google Colab: put six orders in a pandas table, total the quarter and rank customers by revenue, typing every line yourself.

[All 3 modules in Python](https://learn.ynteractive.com/content/course/python)

## Free cheat sheet

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

- [Python for Spreadsheet Work Cheat Sheet](https://learn.ynteractive.com/content/cheat-sheets/python-spreadsheet-work): A free one-page Python cheat sheet for Google Colab: load pandas, total and rank customers, stack monthly exports and clean messy names and amounts.

[All free printable cheat sheets](https://learn.ynteractive.com/content/cheat-sheets)

## Terms in this lesson

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

[pandas (Python)](https://learn.ynteractive.com/content/glossary/pandas) · [Python](https://learn.ynteractive.com/content/glossary/python) · [Duplicate invoice](https://learn.ynteractive.com/content/glossary/duplicate-invoice) · [Invoice](https://learn.ynteractive.com/content/glossary/invoice)

[The full AI glossary](https://learn.ynteractive.com/content/glossary)

## Browse related tutorials

[Python (3)](https://learn.ynteractive.com/content/course/python) · [Google Colab tutorials (3)](https://learn.ynteractive.com/content/tool/google-colab)

Want AI working like this in your business? Robert Breen, the instructor behind this lesson, helps small and mid-sized teams put AI assistants, agents and automations to work. [AI consulting for small teams](https://ynteractive.com/)
