Pandas is the most popular Python library for working with tabular data. Think of it as Excel, but programmable, faster with big datasets, and able to repeat the same steps a million times without getting tired.
Its two stars are the DataFrame (a table with rows and columns) and the Series (a single column). Almost everything you do in finance β loading bank statements, combining ledgers, aggregating monthly totals β can be done in Pandas in just a few lines.
Financial data comes in many shapes. Pandas can read them all:
| Format | Function | Common Use |
|---|---|---|
| CSV | pd.read_csv() | Bank exports, ledger extracts |
| Excel | pd.read_excel() | Monthly reports, statements |
| JSON | pd.read_json() | |
| SQL | pd.read_sql() | Direct from databases |
Real financial data is never perfect. You'll see:
Missing values (a transaction with no amount β oops). Wrong types (a price stored as text). Duplicates (the same row twice from a merge). Inconsistent formats ("$1,234.56" vs "1234.56" vs "1.234,56").
Pandas gives you clear tools: df.dropna(), df.fillna(), df.astype(), df.drop_duplicates(). The rule: clean slowly, document every step.
Financial data always has a date β but dates arrive in many formats: "2024-01-15," "15/01/2024," "Jan 15, 2024." Pandas converts them all with pd.to_datetime(). Once dates are real dates, you can filter by month, group by quarter, and compute "days since last payment."
Currencies need care too: which currency is this amount in? Was it converted on which date? Store amounts alongside their currency, and be careful with conversions. Never mix currencies without a clear exchange rate.
Before you build any model, look at your data. Visualization catches problems instantly: gaps, spikes, flatlines, or suspicious clusters.
Simple charts go a long way: line plots for trends over time, bar charts for category comparisons, scatter plots for two features, histograms for distribution. Pandas can plot quickly with df.plot(), and libraries like Matplotlib and Seaborn add polish.
You'll write your analysis in Jupyter Notebooks (or Google Colab). These let you mix code, output, and notes in one place. But there's a catch: a notebook run out of order gives wrong results.
Best practices: restart & run all before sharing, save cleaned data as a separate file, and version your work (Git). When someone asks "how did you get this number?" β you should be able to point to a single cell and reproduce it.
Some traps catch nearly every financial analyst at least once:
Silent type conversion: a number stored as text won't sum correctly. Mixed date formats: half the rows in one format, half in another. Missing currency: you mix dollars and euros. Trailing spaces: "ACME" β "ACME ". Hidden characters from spreadsheet exports.
Pandas helps you catch these with df.info(), df.describe(), and df.isna().sum(). Always check before you trust.
Load a mini bank statement: Create a small CSV with 10 transactions (date, description, amount). Load it into Pandas. Print the first 5 rows and check the column types with df.info().
Clean the mess: Introduce 2 missing values and 1 duplicate into your dataset. Use df.dropna() and df.drop_duplicates() to clean it. Compare the row counts before and after.
Date practice: Add a "date" column with mixed formats ("2024-01-15" and "15/01/2024"). Convert them all with pd.to_datetime(). Then group your transactions by month and print total spending per month.
Visualize a trend: Plot your transactions over time as a line chart. What do you notice? Are there any gaps, spikes, or missing days? Write one sentence describing what you see.
Detective mode: Check your dataset for common pitfalls: any strings where numbers should be? Any trailing spaces in names? Any missing currencies? Write a 3βline summary of what you found.
Reproducibility check: In your notebook, restart the kernel and run all cells from top to bottom. Does everything work? If not, clean up the order β every analysis should run topβtoβbottom cleanly.
By the end of this module, you'll be able to: load financial data in Pandas, clean messy datasets, handle dates and currencies, visualize trends, organize notebooks reproducibly, and spot common data quality traps before they cause trouble.