Module 2 · pandas Quick Start
Clean, Filter and Calculate
Fix column types, add a revenue column, filter rows that match a condition and sort the results.
About 15 minutes
Open in ColabEvery example as a notebook you can run, edit and save to your Google Drive.
Fix the date column
Dates loaded as text can't be sorted or grouped by month properly. Convert them:
Edit the code and press Run (Ctrl + Enter). Examples on this page share their variables, like cells in a notebook.
order_date is now datetime64. You can pull out parts of the date:
Edit the code and press Run (Ctrl + Enter). Examples on this page share their variables, like cells in a notebook.
Add a revenue column
Revenue for each line is quantity × unit price, minus the discount:
Edit the code and press Run (Ctrl + Enter). Examples on this page share their variables, like cells in a notebook.
Total revenue is ₦830,541,245. Notice there's no loop: pandas does the maths for every row at once.
Filter rows
Put a condition inside square brackets to keep only the matching rows:
Edit the code and press Run (Ctrl + Enter). Examples on this page share their variables, like cells in a notebook.
Combine conditions with & (and) or | (or), with brackets around each one:
Edit the code and press Run (Ctrl + Enter). Examples on this page share their variables, like cells in a notebook.
Sort
Edit the code and press Run (Ctrl + Enter). Examples on this page share their variables, like cells in a notebook.
This shows the five biggest order lines. Use ascending=True (the default) for smallest first.
Check for problems
Real data is rarely this clean. These checks are worth running on any dataset:
Edit the code and press Run (Ctrl + Enter). Examples on this page share their variables, like cells in a notebook.
This dataset passes all three, but make it a habit.
Try it
Continue in the same notebook, after adding the year, month and revenue columns.
Practice
How many order lines had a 10% discount?
Practice
How much revenue did those 10%-discount lines bring in? (A rounded figure is fine.)
Practice
What is the revenue of the biggest single order line in 2026?
Earn your badge
Take the module check
Questions on this module. Pass and you earn the Data Cleaning with Python badge, free.
Create a free account to earn the badge