# Python for spreadsheet work: total, combine and clean exports with pandas

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

Source: https://learn.ynteractive.com/content/cheat-sheets/python-spreadsheet-work · Updated 2026-10-24 · Free from Stepthrough (https://learn.ynteractive.com)

[Lesson cheat sheet](https://learn.ynteractive.com/content/cheat-sheets#kind-lesson) · One page · US letter · [Google Colab](https://learn.ynteractive.com/content/tool/google-colab)

By [Robert Breen](https://learn.ynteractive.com/content/about) · Published October 24, 2026 · From the free lesson [Python: Total a Sales Export by Customer in Google Colab](https://learn.ynteractive.com/content/python-sales-report)

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.

[Download the free PDF (75 KB)](https://learn.ynteractive.com/content/cheat-sheets/python-spreadsheet-work.pdf)Print this sheet

Free, no sign-up and no email needed. It prints on one letter-size page; the whole sheet is below.

*▶*StepthroughFree printable cheat sheet · learn.ynteractive.com

Python for spreadsheet work: total, combine and clean exports with pandas

The three modules of the free Python for Spreadsheet Work Jump Start, practised there on real Google Colab screens.

## Colab basics

**Start**

colab.research.google.com, **New notebook**.

**Run**

**Shift+Enter** runs a cell and opens a new one.

**Load**

`import pandas as pd`

**Read**

`sales = pd.read_csv('sales.csv')` (upload it in the Files panel).

## Total and rank

1. `sales['amount'].sum()` adds one column.
2. `totals = sales.groupby('customer')['amount'].sum()`
3. `totals.sort_values(ascending=False)` biggest first.

## Combine monthly exports

1. Label first: `july['month'] = 'Jul'` (same for each month).
2. `quarter = pd.concat([july, august, september], ignore_index=True)`
3. `quarter.groupby('month', sort=False)['amount'].sum()`

## Clean before you total

1. `df['client'] = df['client'].str.strip().str.title()`
2. `df['amount'] = df['amount'].str.replace(',', '').astype(int)`
3. `df = df.drop_duplicates()` after the clean-up, not before.

## Good habits

- Show the table after every change: its name on the last line.
- Clean, then de-duplicate, then total.
- Keep the notebook: next month only the file name changes.

**Remember:** Write the steps once, run them on every export: same result every time, no missed rows and no double counts.

Practice it free: [Python: Total a Sales Export by Customer in Google Colab](https://learn.ynteractive.com/modules/python-sales-report) at learn.ynteractive.com/modules/python-sales-report. This sheet: learn.ynteractive.com/content/cheat-sheets/python-spreadsheet-work. Lakeside Office Supply is a made-up business from the lesson. By Robert Breen, October 24, 2026.

## Practice it in the free lesson

**Python: Total a Sales Export by Customer in Google Colab**. 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. 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, and nothing touches your real accounts.

[Start the free lesson](https://learn.ynteractive.com/modules/python-sales-report)

[Or read the full step-by-step guide](https://learn.ynteractive.com/content/python-sales-report)

## Lessons on this sheet

- [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.
- [Python: Combine Monthly Sales Exports into One Quarter](https://learn.ynteractive.com/content/python-combine-exports): A beginner Python walkthrough in the free Google Colab: label three monthly exports, stack them into one quarter with pandas concat and total by month and by customer…
- [Python: Clean a Messy Invoice Export Before You Total It](https://learn.ynteractive.com/content/python-clean-invoice-export): 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…

## Related terms

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

[Python](https://learn.ynteractive.com/content/glossary/python) · [pandas (Python)](https://learn.ynteractive.com/content/glossary/pandas) · [CSV](https://learn.ynteractive.com/content/glossary/csv)

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

## More cheat sheets

- [AI Email Responder in n8n Cheat Sheet](https://learn.ynteractive.com/content/cheat-sheets/ai-email-responder-n8n): A free one-page cheat sheet: n8n watches Gmail, an AI agent reads each customer email and saves a reply as a draft in the same thread.
- [AI Receipt Extractor in n8n Cheat Sheet](https://learn.ynteractive.com/content/cheat-sheets/receipt-extraction-setup): A free one-page cheat sheet: attach a receipt photo in n8n chat, and an AI agent pulls the date, vendor and amount into a Google Sheets row.
- [ChatGPT Bank Reconciliation Cheat Sheet](https://learn.ynteractive.com/content/cheat-sheets/chatgpt-bank-reconciliation): A free one-page cheat sheet: match a bank statement CSV to the ledger with ChatGPT, list the exceptions, build the summary and check the math yourself.

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