Lesson 2.3foundation3 h

pandas, data wrangling and plotting

Getting a messy table into a shape a model can learn from

Real data arrives as tables with missing values, inconsistent categories, dates stored as strings and columns that leak the answer. Before any model in 3.2 Linear regression–3.14 Project: end-to-end tabular ML with scikit-learn can run, that table has to be loaded, inspected, cleaned, joined and summarized — and the fastest way to understand a dataset is still a handful of well-chosen plots. pandas and matplotlib are the tools; exploratory data analysis (EDA) is the habit that prevents you from training on garbage.

You'll be able to

  • Load CSV/Parquet files into a DataFrame and inspect shape, dtypes, missingness and summary statistics
  • Select rows and columns with loc/iloc and boolean conditions without chained-assignment bugs
  • Compute grouped aggregates, pivot tables and joins, and reshape between wide and tidy formats
  • Handle missing values, categorical and datetime columns deliberately
  • Produce the five core EDA plots and read them for outliers, skew, leakage and class imbalance

Key ideas

  1. A DataFrame is a labelled dictionary of typed columns; the first five minutes are shape, head, info, describe, value_counts and missingness.
  2. loc selects by label, iloc by position; combine masks with & | ~ and assign through a single .loc to avoid chained-indexing bugs.
  3. groupby → agg reduces per group, transform aligns results back to rows; pivot_table is a groupby in grid form.
Show 5 more key ideas
  1. Check row counts around every merge; use validate= to catch many-to-many explosions.
  2. Tidy data (one variable per column, one observation per row) makes grouping, plotting and modelling uniform; melt and pivot convert.
  3. Missingness is information: decide drop/impute/indicator deliberately and fit imputers on training data only.
  4. Five plots (histogram, bar, scatter, box, correlation heatmap) catch skew, imbalance, outliers and leakage before modelling.
  5. Parquet beats CSV for anything you save yourself: typed, compressed, columnar.

Suggested path through this lesson