Welcome, young data explorer! In this module, we will learn how to make our data sparkly clean. Imagine you have a big bowl of fruits. Some fruits are rotten, some have dirt, and some are not even fruits! You wouldn't want to eat that, right? In the same way, when we work with data, we must clean it before we use it. Cleaning data means fixing mistakes, removing things we don't need, and making everything neat and tidy. This is a very important job for a data analyst. After this lesson, you will be a Data Cleaning Champion!
Chidi loves helping his mum at the market. One day, his mum gave him a messy list written on a crumpled paper. The list had things like:
milk, MILK, 2 milk, eggs, egg, 5 eggs, bread, bred, butter, buter, jam
Chidi was confused! Some items were repeated, some were spelled wrong, and some had numbers mixed in. He decided to clean the list. He crossed out the repeated "milk", fixed "bred" to "bread", and wrote "butter" correctly. Then he grouped all the eggs together. After cleaning, the list was perfect, and his mum was very happy. That is exactly what we do with data in Power Query โ we clean it so that it makes sense!
Definition: Data cleaning is the process of finding and fixing errors in data.
Why important: Dirty data gives wrong answers. Clean data gives correct answers.
Simple explanation: It's like washing your hands before eating. You remove germs (errors) so you don't get sick (wrong results).
Real-life example: A teacher has a list of students. Some names are spelled wrong. She corrects them. That's cleaning.
School example: Your class register has duplicate names. You remove them.
Home example: You have a list of chores. Some chores are written twice. You delete the extras.
Nigerian example: A shopkeeper in Lagos records sales. Some entries say "N500" and others say "500 Naira". He makes them all "500 Naira".
Illustration:
Dirty Data โก๏ธ Clean Data ----------------- ----------------- Name: Tunde Name: Tunde Age: 25 Age: 25 City: Lagos City: Lagos Name: Tunde (dup) (removed)
Mini summary: Data cleaning fixes mistakes so our data is accurate and useful.
Definition: Duplicate rows are rows that are exactly the same as another row.
Why important: Duplicates make counts wrong (e.g., counting the same person twice).
Simple explanation: Imagine you have a list of your friends. If "Ade" appears twice, you might think you have two friends named Ade. But it's the same person. So we remove one.
Real-life example: A company sends newsletters. If email addresses are duplicated, people get two emails. They get annoyed.
School example: Your teacher has a list of students who brought books. If a student is listed twice, the count is wrong.
Home example: Your family grocery list has "rice" written three times. You keep only one.
Nigerian example: A bank in Abuja records transactions. The same transaction might be entered twice by mistake. Removing duplicates fixes the balance.
How to do it in Power Query: Select your table, go to the "Home" tab, click "Remove Rows", then "Remove Duplicates".
Illustration:
Before: After: +----+-------+ +----+-------+ | ID | Name | | ID | Name | +----+-------+ +----+-------+ | 1 | Bola | | 1 | Bola | | 2 | Tayo | | 2 | Tayo | | 1 | Bola | โ dup | 3 | Zain | | 3 | Zain | +----+-------+ +----+-------+
Mini summary: Use "Remove Duplicates" to delete rows that are identical.
Definition: Missing values are empty cells in your data.
Why important: Blanks can cause errors in calculations (e.g., sum of blank is zero, but maybe you wanted to ignore it).
Simple explanation: If a form asks for your age and you leave it blank, the computer doesn't know your age. We can fill it with something like "Unknown" or the average age.
Real-life example: A survey has some questions unanswered. We can fill them with "No answer".
School example: A test score list has a blank for a student who was absent. We can write "Absent".
Home example: A list of birthdays has a missing date. We can write "Not known".
Nigerian example: A hospital in Kano has patient records. Some have no phone number. They fill with "0000".
How to do it: In Power Query, use "Replace Values" to replace null or blank with something else. Or use "Fill Down" to copy the value from above.
Illustration:
Before: After (Fill Down): +----+-------+ +----+-------+ | Day| Temp | | Day| Temp | +----+-------+ +----+-------+ | Mon| 30ยฐ | | Mon| 30ยฐ | | Tue| | | Tue| 30ยฐ | โ copied from Mon | Wed| 28ยฐ | | Wed| 28ยฐ | +----+-------+ +----+-------+
Mini summary: Fill blanks with a value or copy from above to avoid empty cells.
Definition: Splitting means dividing one column into two or more columns.
Why important: Sometimes one column has too much information (e.g., "First Name Last Name"). We split it to separate first and last names.
Simple explanation: If you have a jar of mixed sweets, you separate the red ones from the green ones. That's splitting.
Real-life example: A column has "City, State". We split into "City" and "State".
School example: A column has "Subject-Grade" like "Math-A". Split into "Subject" and "Grade".
Home example: A list of "Item-Qty" like "Apples-5". Split into "Item" and "Qty".
Nigerian example: A column has "LGA, State" like "Ikeja, Lagos". Split into "LGA" and "State".
How to do it: Select the column, go to "Transform" tab, click "Split Column", choose "By Delimiter" (like a comma or space).
Illustration:
Before: After: +----------------+ +---------+---------+ | Full Name | | First | Last | +----------------+ +---------+---------+ | Chidi Okonkwo | | Chidi | Okonkwo | | Amina Bello | | Amina | Bello | +----------------+ +---------+---------+
Mini summary: Split columns to separate data that is combined.
Definition: Data type tells Power Query what kind of data is in a column (text, number, date, etc.).
Why important: If you have numbers stored as text, you cannot add them. So you must change to number type.
Simple explanation: It's like sorting toys: cars go in the car box, dolls in the doll box. You put each data in its correct box.
Real-life example: A column has "1000" but it is text. You change it to number so you can sum it.
School example: "Age" column has numbers but is stored as text. You change to number to calculate average age.
Home example: "Price" column has "โฆ500" but with a symbol. You remove the symbol and change to number.
Nigerian example: "Date of Birth" is stored as text "12-05-2010". Change to Date type to calculate age.
How to do it: Click the little icon next to the column header (like "ABC" or "123") and choose the correct type (Text, Whole Number, Decimal, Date).
Illustration:
Before (Text) After (Number) +-------+ +-------+ | Price | | Price | +-------+ +-------+ | 500 | | 500 | | 1000 | | 1000 | +-------+ +-------+ (Can't sum) (Can sum = 1500)
Mini summary: Always set the right data type so Power Query can work properly.
Definition: Renaming means changing the name of a column.
Why important: Sometimes column names are not clear (e.g., "Col1"). We rename to something meaningful like "Student Name".
Simple explanation: It's like putting a label on a box so you know what's inside.
Real-life example: A column named "B" actually contains "Age". Rename it to "Age".
School example: "X" column is "Score". Rename to "Math Score".
Home example: "Item" column is actually "Fruit". Rename to "Fruit".
Nigerian example: "Column1" is "State". Rename to "State of Origin".
How to do it: Double-click the column header and type the new name. Or right-click and choose "Rename".
Illustration:
Before: After: +------+ +---------+ | Col1 | | Student | +------+ +---------+ | Ade | | Ade | +------+ +---------+
Mini summary: Give columns clear, descriptive names.
Definition: Trimming removes unwanted spaces at the beginning or end of text.
Why important: " Bola " is not the same as "Bola". Extra spaces can cause problems when you compare or group.
Simple explanation: Imagine writing your name with a big space before it. That looks messy. We erase the space.
Real-life example: A list of cities has " Lagos" and "Lagos". They should be the same. Trim them.
School example: " John " and "John" are different to a computer. Trim to make them match.
Home example: " rice " and "rice" should be the same when searching.
Nigerian example: " Abuja" and "Abuja " are both Abuja after trimming.
How to do it: Select the column, go to "Transform" tab, click "Format", then "Trim".
Illustration:
Before: After: " Bola " "Bola" "Tunde " "Tunde" " Amina" "Amina"
Mini summary: Trim to remove extra spaces and make text clean.
Definition: Replacing means changing one value to another (e.g., change "N/A" to "Not Available").
Why important: Standardizes data. For example, "Yes", "Y", "y" all mean the same. We replace them all with "Yes".
Simple explanation: If you have different names for the same thing, you pick one name and use it everywhere.
Real-life example: "Male", "M", "m" all become "Male".
School example: "Absent", "A", "a" all become "Absent".
Home example: "Phone", "tel", "mobile" all become "Phone".
Nigerian example: "Naira", "NGN", "โฆ" all become "Naira".
How to do it: Right-click the column, choose "Replace Values", enter what to find and what to replace with.
Illustration:
Before: After: +-------+ +-------+ | Status| | Status| +-------+ +-------+ | Y | | Yes | | N | | No | | y | | Yes | +-------+ +-------+
Mini summary: Replace values to make your data uniform.
Definition: Remove rows means deleting certain rows from your table.
Why important: Sometimes you only need a portion of data (e.g., first 10 rows for a sample).
Simple explanation: If you have a long queue, you might only talk to the first 5 people.
Real-life example: You have 1000 rows but only want top 100 for testing.
School example: You have a list of 50 students but only need top 5.
Home example: You have a list of 20 groceries but only want the first 3 for a quick check.
Nigerian example: A store in Ibadan has 200 sales records but only wants the latest 10.
How to do it: Home tab โ Remove Rows โ Remove Top Rows, Remove Bottom Rows, or Remove Alternate Rows.
Illustration:
Before (10 rows) After Remove Top 3 (7 rows left) +----+-----+ +----+-----+ | 1 | A | | 4 | D | | 2 | B | โ remove | 5 | E | | 3 | C | โ remove | 6 | F | | 4 | D | | 7 | G | | 5 | E | | 8 | H | ... ... +----+-----+ +----+-----+
Mini summary: Remove rows you don't need to focus on important data.
Definition: Keep rows means you select and keep only certain rows, deleting all others.
Why important: This is the opposite of remove rows. You choose what to keep.
Simple explanation: It's like picking only the red marbles from a bag and leaving the rest.
Real-life example: You have sales data for all months but only want January to March.
School example: You have grades for all subjects but only want Science grades.
Home example: You have a list of all bills but only want electricity bills.
Nigerian example: You have data for all states but only want Lagos and Abuja.
How to do it: Home tab โ Keep Rows โ Keep Top Rows, Keep Bottom Rows, Keep Range of Rows.
Illustration:
Before (10 rows) After Keep Top 2 (only 2 rows) +----+-----+ +----+-----+ | 1 | A | โ keep | 1 | A | | 2 | B | โ keep | 2 | B | | 3 | C | remove | | | | 4 | D | remove | | | ... ... +----+-----+ +----+-----+
Mini summary: Keep only the rows that matter to you.
Definition: Fill Down copies the value from the cell above to the empty cells below.
Why important: Useful when you have a header that applies to multiple rows (e.g., a category).
Simple explanation: If you have a list of fruits, and "Apple" is written once, you can fill down so all apples have that label.
Real-life example: A sales table where the region is only written in the first row of each region. Fill down to fill all rows.
School example: A class list where the teacher's name is only in the first row. Fill down for all students.
Home example: A chore list where the day is written once. Fill down for all chores on that day.
Nigerian example: A table of LGA's, only the state is written once. Fill down to show state for every LGA.
How to do it: Select the column, go to "Transform" tab, click "Fill" and choose "Down".
Illustration: (See Lesson 3 illustration).
Mini summary: Fill Down copies the upper value to lower empty cells.
Definition: Fill Up copies the value from the cell below to the empty cells above.
Why important: Less common but useful when the first row is blank and the data starts later.
Simple explanation: Same as Fill Down but going upwards.
Real-life example: A table where the header is at the bottom. Fill up to move it to the top.
School example: A list where the last row has the correct value for all above.
Home example: A shopping list where the total is at the bottom, fill up to give each item the total.
Nigerian example: A report where the summary is at the bottom, fill up to apply to all.
How to do it: Transform tab โ Fill โ Up.
Illustration:
Before: After Fill Up: +-------+ +-------+ | | | 50 | โ copied from below | | | 50 | | 50 | | 50 | +-------+ +-------+
Mini summary: Fill Up copies the lower value to upper empty cells.
Definition: This means doing many cleaning actions one after another.
Why important: Real data needs many fixes. You combine them to get a perfect table.
Simple explanation: It's like a recipe: first wash the vegetables, then chop them, then cook them.
Real-life example: A data set: remove duplicates, trim spaces, change types, rename columns.
School example: A grade sheet: remove missing, change text to numbers, sort.
Home example: A budget: replace categories, split amounts, fill missing.
Nigerian example: A COVID-19 data: remove duplicate entries, fix date format, replace missing with "0".
How to do it: In Power Query, each step appears in the "Applied Steps" pane. You can reorder or delete steps.
Illustration: (Flow chart)
Start
|
V
Remove Duplicates
|
V
Trim Spaces
|
V
Change Data Types
|
V
Rename Columns
|
V
Done
Mini summary: Combine steps to clean data thoroughly.
Definition: Replace Errors changes error values (like #Error) to something else.
Why important: Errors stop calculations. Replacing them with 0 or "Unknown" lets you continue.
Simple explanation: If a math sum gives an error, you can say "let's treat it as zero".
Real-life example: A column has "5/0" which gives error. Replace with 0.
School example: A formula column has errors. Replace with "N/A".
Home example: A budget column has errors. Replace with 0.
Nigerian example: A financial report has division by zero errors. Replace with 0.
How to do it: Right-click the column โ Replace Errors โ type the replacement value.
Illustration:
Before: After: +-------+ +-------+ | #Error| | 0 | | 10 | | 10 | +-------+ +-------+
Mini summary: Replace errors to avoid breaking your analysis.
Definition: Pivot turns rows into columns. Unpivot turns columns into rows.
Why important: Sometimes data is in a "wide" format, but you need "long" format for analysis.
Simple explanation: If you have a table with months as columns, unpivot makes a "Month" column and a "Value" column.
Real-life example: Sales data with Jan, Feb, Mar as columns. Unpivot to have Month and Sales rows.
School example: A table with subjects as columns. Unpivot to have Subject and Score rows.
Home example: A budget with months as columns. Unpivot for easier charting.
Nigerian example: A table with states as columns. Unpivot to have State and Population rows.
How to do it: Select columns, right-click โ Unpivot Columns. Or Pivot on a column.
Illustration:
Wide (Pivot) Long (Unpivot)
+----+-----+-----+ +----+-------+-------+
|Year| Jan | Feb | |Year| Month | Sales |
+----+-----+-----+ +----+-------+-------+
|2024| 100 | 150 | โก๏ธ |2024| Jan | 100 |
+----+-----+-----+ |2024| Feb | 150 |
+----+-------+-------+
Mini summary: Pivot/Unpivot reshapes your data for different needs.
How to remove duplicates:
How to split a column by delimiter:
Did you know that the word "data" comes from Latin, meaning "given" (like a gift). But dirty data is not a gift โ it's a headache! So we clean it.
Start
|
V
Load Data
|
V
Remove Duplicates
|
V
Replace Missing Values
|
V
Split Columns (if needed)
|
V
Change Data Types
|
V
Trim Spaces
|
V
Rename Columns
|
V
Done ๐
+----------------------------+ +----------------------------+ | Dirty Data | | Clean Data | +----------------------------+ +----------------------------+ | Name: " Ade " | | Name: "Ade" | | Age: "25" (text) | | Age: 25 (number) | | City: "Lagos, Nigeria" | | City: "Lagos" | | | | Country: "Nigeria" | | Duplicate row of Ade | | (Duplicate removed) | +----------------------------+ +----------------------------+
| Feature | Remove Rows | Keep Rows |
|---|---|---|
| What it does | Deletes selected rows | Keeps selected rows, deletes others |
| Use when | You want to exclude data | You want to focus on specific data |
| Example | Remove top 5 rows | Keep top 5 rows |
| Feature | Fill Down | Fill Up |
|---|---|---|
| Direction | Copies from above to below | Copies from below to above |
| Use when | Header is at the top | Header is at the bottom |
| Common | Very common | Less common |
Well done! You have completed Module Seven on Data Cleaning. You learned:
Cleaning data is like being a detective โ you find clues (errors) and fix them. Now you are ready to clean any messy data!
Match the term to its definition:
| Term | Definition |
|---|---|
| 1. Trim | A. Copy value from above |
| 2. Fill Down | B. Remove extra spaces |
| 3. Duplicate | C. Divide one column into two |
| 4. Split | D. Identical row |
| 5. Data Type | E. Kind of data (text, number, date) |
Answers: 1-B, 2-A, 3-D, 4-C, 5-E
Scenario 1: You have a list of students with names, ages, and grades. Some ages are blank, some names have extra spaces, and there are duplicate rows for a student. What steps would you take to clean this data?
Scenario 2: A store in Lagos has sales data with columns: "Product", "Price (โฆ)", "Date". The "Price" column has "โฆ" symbols and spaces. How would you clean this data to calculate total sales?
In groups of 3, download a sample dataset with messy data (or create one). Assign each person a cleaning task: one removes duplicates, one trims and replaces, one changes data types. Then combine the cleaned data.
Take a messy list of 20 names (some with spaces, duplicates, typos). Use Power Query to clean it: trim, remove duplicates, fix typos, and rename the column. Write down the steps you took.
Project: Clean a School Dataset
You are given a dataset of 100 students with columns: StudentID, Name, Class, Score. The dataset has duplicates, missing scores, and inconsistent names (some have extra spaces, some are in uppercase/lowercase). Clean the dataset using Power Query. Present the cleaned table in class.
Download a CSV file from the internet (e.g., a sample sales dataset). Use Power Query to:
You have a dataset with sales for 5 years, each year as a separate column (2019, 2020, 2021, 2022, 2023). Unpivot this data to create a "Year" column and a "Sales" column. Then clean the data: remove any rows with sales less than 0, and replace any missing years with the average of the previous and next year.
Fill-in-the-Blank: 1. errors, 2. Duplicate, 3. Trim, 4. data type, 5. Fill Down
True/False: 1-F, 2-F, 3-T, 4-F, 5-F
Matching: 1-B, 2-A, 3-D, 4-C, 5-E
In Module Eight, we will learn about Combining Data โ how to merge and append tables. We will join data from different sources, just like putting puzzle pieces together. Get ready to become a Data Merger!
Before the next class, practice cleaning at least three different datasets. The more you clean, the better you become.
ยฉ 2025 Certified Power Query for Data Analysis Expert โ Module Seven