Trial Balance and General Ledger Analysis in Python — 30 Worked Answers (pandas)
A trial balance is the ledger summed by account — every debit and every credit, and the proof that the two agree. This notebook builds one from 57,978 journal lines in pandas, then uses it the way a finance team does: the profit and loss account by reporting line, the margin by year and by month, actuals against the budget, and finally a bridge that splits the change in gross profit into the part that came from selling more and the part that came from selling at a thinner margin.
By findi360 · Updated November 2026
- Format
- Jupyter notebook (.ipynb), outputs saved
- Data
- DATA DARE DD-GLT-001 · 57,978 journal lines · 2024 to September 2026
- Covers
- 30 questions, easy to very hard
- Needs
- Python 3.9+, pandas, openpyxl
The one rule the whole notebook rests on
Every ledger line carries a debit and a credit, and one of the two is zero. Debits are positive and credits are negative, so a single signed column — debit minus credit — describes any line. A cost account is read as it stands; an income account is read with the sign flipped, because income arrives as a credit. Get that one rule right at the start and everything after it, from the trial balance to the margin bridge, falls out without a single lookup table.
From trial balance to profit and loss
The trial balance groups the signed amount by account and year. The profit and loss account groups the same thing by reporting line, with the sign flipped so income is positive and costs are negative — which makes gross profit a plain addition of revenue and cost of sales rather than a subtraction with a sign to remember. Both tables are built once, early, and every question afterwards reads off them.
Actuals against budget, and the gross profit bridge
The budget is held by account and period, so it joins to the same reporting lines as the actuals and the variance is a subtraction. The bridge is the more interesting piece: revenue grew by eleven per cent while gross profit grew by less than five, and the notebook separates the two causes — the volume effect, which is the extra revenue at last year's margin, and the margin effect, which is this year's revenue at the change in margin. That is the sentence a CFO actually wants.
The accrual that was never reversed
The last questions are an audit exercise. Month-end accruals are supposed to be reversed the following month by a journal that points back at them. One was not, and it is still sitting in the ledger overstating costs. Finding it means matching reversal journals to the accruals they undo, and noticing that the final month of the data would be reversed in a month the file does not contain.
Python or Excel?
A trial balance of eighty accounts fits comfortably in Excel. Fifty-eight thousand journal lines behind it do not, and neither does doing the same work again next month. The notebook reads the ledger, proves it balances, and rebuilds every statement from it in seconds — which is also how you would check an Excel model that someone else built.
Inside the notebook
- Libraries — A cell that tells you which libraries are missing before anything else runs.
- Load the sheets — One workbook, five sheets: the ledger, the accounts, the cost centres, the calendar and the budget.
- First look — Column types, the journal types in the ledger and the shape of the chart of accounts.
- Fix the data — The year, the signed amount, and the account attributes joined onto every line.
- Four working tables — Trial balance, profit and loss by reporting line, the same by month, and the budget.
- The answers, Q01 to Q30 — One cell per question, each ending with the answer, and a final list of all thirty.
Excel + Python — the Power of Plus
Excel does this model well when all five of these are true. When two or more are not, you add Python — not instead of Excel, beside it. That is the Power of Plus.
- One-off — you build it once, not again every month.
- Fixed structure — the same accounts, entities and layout each time.
- Small enough to check by eye — thousands of rows, not millions.
- One source — one ledger or one plan, not data scattered across systems and files.
- No live link needed — nobody expects it to update from the ledger by itself.
What next month's close really costs in Excel
- Export the ledger again and paste 58,000 rows into a sheet that is already near its limit.
- Rebuild the pivot, re-point every SUMIFS and check that nothing fell outside the range.
- Re-check the trial balance by eye, and hope a journal that does not balance is visible.
- Repeat the budget comparison and the margin bridge by hand, with the same risk of a stale reference.
The same work, once it repeats
In Python the statements rebuild from the new export in seconds, the balance check is a single line, and an out-of-balance journal cannot hide.
Python still needs your judgement where the data is new — but everything after that repeats by itself.
Learn it on findi360: Python for Finance — Advanced Analytics & Reporting
Notify me when it opensWant to see what scattered data looks like? Three ERPs, three currencies and one consolidated group: DD-CON-004 — Diversified Group Close: Acquisition, Goodwill & Multi-ERP Consolidation
Who this model is for
- Accountants and controllers who close the books and want the statements rebuilt from the ledger rather than re-keyed
- Auditors testing a general ledger — balance, accruals, reversals and cut-off
- Finance people learning Python who want to start from something they already understand
Frequently asked questions
Do I need to know Python already?
No. Each block of code is introduced in plain words first, and the comments say why a line is there rather than what it does. If you can follow a trial balance you can follow this file.
What is a trial balance, in one line?
The ledger summed by account: every debit and every credit at a date. It balances when the two totals agree, which is the first thing the notebook checks — and it checks every individual journal as well, not just the total.
Can I run it on my own ledger?
Yes, once the column names match. The notebook expects a journal line with an account, a period, a debit and a credit, plus a chart of accounts that says which reporting line each account belongs to. Point the loading cell at your own export and the rest follows.
Which version of pandas does it need?
It was run and checked on pandas 2.2.3 and 3.0.5 and gives identical answers on both.
Are the answers correct?
All thirty were compared with the Expected_Result_Value in the dataset's Question Bank, on two versions of pandas, before the file was published.
Keep going on findi360
- DATA DARE Mizan Retail: Sales Up, Profit Down — Journals, Trial Balance and Budget DD-GLT-001 · L1 — XLSX / ~10,000 rows Three Companies, Four Dates, One Close — GL, Trial Balance, Bank and Budget DD-GLT-003 · L3 — Parquet / ~500,000 rows
- DATA DRILL Test yourself — Power BI practice questions One question at a time, or a 50-question timed simulation.
- GUIDE Trial balance in Python The same work in Python, with tested code and its real output.
- COURSE Courses and free recordings Power BI, Python and finance courses for finance professionals.
Related models
-
AR Analysis in Python — Jupyter Notebook
A complete receivables working file in pandas: load four file formats, append the new quarter, build six working tables, then answer forty graded questions — from the ageing bucket to the overdue book corrected for cash nobody could place.
-
Accounts Payable in Python — Jupyter Notebook
The purchase ledger worked end to end: what is owed at any date, how much of it is overdue, how long suppliers really wait for their money, and the invoices that were posted twice and are still sitting in the balance.
-
Payroll Analysis in Python — Jupyter Notebook
Payroll analysed the way HR and finance actually report it: headcount at a date, joiners and leavers, turnover on an average headcount, cost per head, overtime by store, and the end-of-service liability worked employee by employee.
Need a model we have not built yet?
Tell us what you need. Members vote, and the most-requested models are built first — free to download.
Educational model on illustrative data. Not investment, accounting or tax advice. © findi360 — share freely with attribution.
