fazalehaq.comSaved
AIDBDRILLCTOOLDLEVELESTATUS
← LAB

Python / Intro / Free practice

Clean a Messy Finance Extract with Python

Take a typical finance extract with mixed headers, blank rows, and inconsistent account codes, and produce a clean, analysis-ready table.

Preview / read-only

>>> df.shape
(4821, 14)
>>> df.columns[:4].tolist()
['Acct', 'Acct Name', 'Period', 'Amt']
>>> df['Amt'].sum()
# → must tie to TB control

// Notebook fragment — shape check before rename

01

Prerequisites

  • Basic Python (pandas installed)
  • A sample CSV or Excel extract (any messy P&L or trial-balance style file)
02

Procedure

Run the drill

  1. 01

    Load the file and inspect shape, null rates, and header rows before trusting column names.

    Step
  2. 02

    Normalize column names and drop empty rows that arrived from export formatting.

    Step
  3. 03

    Standardize account codes and map known aliases to a single chart-of-accounts key.

    Step
  4. 04

    Add validation checks: totals that must tie, required fields that cannot be blank, duplicates that need review.

    Step
  5. 05

    Write a clean output table plus a short exception log for anything that failed a check.

    Step
OUTPUT

Expected outcome

A reusable cleanup pattern you can adapt to SAP, ERP, or spreadsheet exports — with an exception log you can trust before analysis begins.

Target state

// Bring your own extract; no starter file required