Home / Learn / Data & AI / Python pandas for analysis
All lessons

Python pandas for analysis: clean, group, join and reshape data

Learn pandas by doing: real Python runs in the page, so every example can be edited and run, and every exercise checks your answer. Cleaning, filtering, grouping, joins, reshaping, dates and the analyses employers ask for, ending with a retail analysis notebook for your portfolio.

For analysts and career changers who know a spreadsheet and want Python. No Python needed to start; Module 1 teaches the little you need. Free, no sign-up. All 49 lessons, about 16.7 hours.

What you will be able to do

  • Load and explore any table: CSV and Excel files, a first look with head, info and describe, and picking out the rows and columns you need.
  • Clean messy exports: missing values, duplicates, wrong types, untidy text and mixed date formats, with checks that prove the data is right.
  • Summarise and combine: groupby, pivot tables, joins between tables, and reshaping between wide and long.
  • Work with dates: weekly and monthly totals, rolling averages and year-over-year growth.
  • Do the analyses employers ask for: KPI tables, Pareto, RFM segments, cohort retention and A/B tests.

Real Python runs in this page: every example can be changed and run, and every exercise has Run, Check, Hint and Show answer, with no sign-up and nothing to install. The first run downloads Python once (about 20 MB); after that it works offline. You finish with a retail analysis notebook for your GitHub portfolio. The statistics behind the analyses are in Statistics for analysts.

0 of 49 lessons done

Without the tick, your progress lasts until you close this tab. Either way it stays in this browser: there is no sign-up and nothing is sent to us.

All modules

Part A: Getting data in shape

1 Getting started 6 lessons

  1. 1.1 Why pandas, and how to use this course
  2. 1.2 Just enough Python
  3. 1.3 Series: one column of data
  4. 1.4 DataFrames: a table in Python
  5. 1.5 Reading CSV and Excel files
  6. 1.6 A first look: head, info, describe

2 Selecting and filtering 6 lessons

  1. 2.1 Selecting columns
  2. 2.2 Rows and cells with loc and iloc
  3. 2.3 Filtering rows with conditions
  4. 2.4 Sorting and top-N
  5. 2.5 New columns from calculations
  6. 2.6 query, isin and between

3 Cleaning data 7 lessons

  1. 3.1 Missing values: find, fill or drop
  2. 3.2 Duplicates
  3. 3.3 Data types and converting them
  4. 3.4 Cleaning text with .str
  5. 3.5 Dates and times
  6. 3.6 Checking data: ranges, rules and outliers
  7. 3.7 Cleaning a messy export, start to finish

Part B: Summarising and combining

4 Grouping and aggregating 5 lessons

  1. 4.1 groupby: split, apply, combine
  2. 4.2 Several summaries at once with agg
  3. 4.3 transform and filter: group results on every row
  4. 4.4 value_counts and crosstab
  5. 4.5 Bins and bands with cut and qcut

5 Combining tables 4 lessons

  1. 5.1 Stacking tables with concat
  2. 5.2 Joining tables with merge
  3. 5.3 Join pitfalls: duplicates, keys and validate
  4. 5.4 Lookups with map and replace

6 Reshaping 5 lessons

  1. 6.1 Pivot tables
  2. 6.2 Wide to long with melt
  3. 6.3 Long to wide with pivot, stack and unstack
  4. 6.4 MultiIndex without the fear
  5. 6.5 Tidy data: which shape for which job

Part C: Analysis patterns

7 Time series 5 lessons

  1. 7.1 Dates as the index
  2. 7.2 Daily to weekly and monthly with resample
  3. 7.3 Rolling averages
  4. 7.4 Growth rates: shift, pct_change and year over year
  5. 7.5 Weekdays, months and fiscal periods

8 Analyses employers ask for 8 lessons

  1. 8.1 Readable pandas: method chaining and assign
  2. 8.2 A KPI summary table
  3. 8.3 Pareto and ABC analysis
  4. 8.4 RFM customer segmentation
  5. 8.5 Cohort retention tables
  6. 8.6 Analysing an A/B test in pandas
  7. 8.7 pandas for SQL, Excel and DAX users
  8. 8.8 Fast pandas: vectorise, avoid loops

9 Capstone and interviews 3 lessons

  1. 9.1 Capstone: a retail analysis notebook
  2. 9.2 pandas interview questions, answered
  3. 9.3 pandas cheat sheet