Day 03 Part 2 — NumPy and Pandas: Agenda¶
NumPy and Pandas are the foundation of Python data analysis. NumPy gives you fast numerical computation on arrays. Pandas gives you the DataFrame — a table you can slice, filter, aggregate, join, and visualise with a few lines of code. These two libraries are why Python became the dominant data science language.
Session Overview¶
Duration: 3 hours
Prerequisite: Python for Analytics (lists, dicts, functions)
Tools: Jupyter Lab with numpy and pandas installed
Learning Objectives¶
By the end of this session you will be able to:
- Create and operate on NumPy arrays
- Create Pandas DataFrames from CSV files and dicts
- Inspect a DataFrame:
.shape,.info(),.describe(),.head() - Select rows and columns using labels and positions
- Filter rows with boolean indexing
- Use
.groupby()to aggregate data - Merge DataFrames with
.merge() - Apply functions with
.apply()and.map() - Chain operations using the Pandas method chain pattern
Session Flow¶
| Time | Topic | File |
|---|---|---|
| 0:00 – 0:30 | NumPy arrays — fast numerical computation | 01-numpy-arrays |
| 0:30 – 1:15 | Pandas DataFrames — creation, inspection, selection | 02-pandas-dataframes |
| 1:15 – 1:45 | Filtering data — boolean indexing, query | 03-filtering-data |
| 1:45 – 2:30 | GroupBy and merge | 04-groupby-and-merge |
| 2:30 – 3:00 | Data analysis workflow + mini project | 05-data-analysis-workflows |
Key Imports¶
Always import with these standard aliases:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
pd.set_option("display.max_columns", 50) # show all columns
pd.set_option("display.float_format", "{:,.2f}".format) # format numbers
NumPy vs Pandas — When to Use Which¶
| Task | NumPy | Pandas |
|---|---|---|
| Fast maths on arrays | ✓ | — |
| Matrix operations | ✓ | — |
| Tabular data with column names | — | ✓ |
| Time series | — | ✓ |
| GroupBy aggregation | — | ✓ |
| Data from CSV | — | ✓ |
| Feeding data into ML models | ✓ | ✓ |
Pandas builds on NumPy — DataFrame columns are NumPy arrays under the hood.