Python Mini Projects for Beginners: 5 Practice Projects Before Learning pandas
P13.2 Python Project 2: Bank Statement Summary from a CSV File
Why. Banks export statements as CSV. A quick summary of money in, money out and top spending categories is a real-world task.
What. We read a CSV, convert amounts safely, and total by type and category.
How.
Summarise a statement
- Read rows with csv.DictReader.
- Convert amount with try/except; count bad rows.
- Add positive amounts to income, negative to spending.
- Total spending by category with a dictionary.
- Print the summary, biggest category first.
Worked example A — Read and summarise.
Step 1 — What we do. A salaried customer's March statement.
Step 2 — Make the input file statement.csv in the same folder as your code:
date,description,category,amount
2026-03-01,Salary,income,85000
2026-03-02,Rent,housing,-25000
2026-03-05,Groceries,food,-4200
2026-03-09,Electricity,bills,-1850
2026-03-12,Restaurant,food,-1600
2026-03-20,Bad row,food,abc
About this data: each line is one bank transaction: date, description, category, and amount in ₹ (positive = money in, negative = money out). One row has a bad amount on purpose.
Step 3 — Type and run this code.
import csv
income = spend = 0
by_cat = {}
bad = 0
with open("statement.csv", newline="", encoding="utf-8") as f:
for row in csv.DictReader(f):
try:
amt = float(row["amount"])
except ValueError:
bad += 1
continue
if amt > 0:
income += amt
else:
spend += -amt
by_cat[row["category"]] = by_cat.get(row["category"], 0) + -amt
print(f"Income: ₹{income:,.0f} Spending: ₹{spend:,.0f} Saved: ₹{income - spend:,.0f}")
for cat, amt in sorted(by_cat.items(), key=lambda kv: kv[1], reverse=True):
print(f" {cat:<8} ₹{amt:,.0f}")
print("Bad rows skipped:", bad)
Step 4 — Output you should see.
Income: ₹85,000 Spending: ₹32,650 Saved: ₹52,350
housing ₹25,000
food ₹5,800
bills ₹1,850
Bad rows skipped: 1
Step 5 — What it means. Files + errors + dictionaries + sorting in one small script. pandas will make this even shorter.
Ravindra Bagale's Tip
Always print how many rows were skipped. A summary that hides bad data is a dangerous summary.
Ravindra Bagale's Tip – मराठी
किती rows skip झाल्या ते नेहमी print करा. खराब data लपवणारा summary धोकादायक असतो.
Ravindra Bagale's Tip – हिंदी
कितनी rows skip हुईं, ये हमेशा print करो. खराब data छिपाने वाला summary ख़तरनाक होता है.