Coding Grandmaster ยท project 33 of 46 ยท premium, free for now
Cleaning messy data
Write fill_missing(values) that replaces each None with the mean of the other values rounded to 1 decimal place, and remove_duplicates(values) that keeps only the first of each repeated value in order. Print both results for the readings.
Learn
Real data has gaps and repeats. Before analysing it you decide how to fix it. A common choice for numbers is to fill each gap with the mean of the values you do have; for lists of items you may need to drop duplicates while keeping the first occurrence in order. Writing each fix as its own small function keeps the cleaning clear and testable.
Your task
Write fill_missing(values) that replaces each None with the mean of the other values rounded to 1 decimal place, and remove_duplicates(values) that keeps only the first of each repeated value in order. Print both results for the readings.
Stretch challenge
Use the median instead of the mean to fill gaps. When is that better?
Press Run to see what your program prints.
More in this module
Keep going in Coding Grandmaster
Records, filters and rankings
Keep the students whose score is at least cutoff, sort them by highest score (ties by name), print how many qualified, and print the first top of them as a numbered list.
Start โ32Group by: totals per region
For every sale of at least minimum, add it to its region. Print one line per region (alphabetical) like east: total 360, average 180.0, orders 2.
Start โ34Draw a bar chart
Draw one filled bar for each value, 40 wide and 15 times the value tall, 50 apart, starting at x = -150 along the line y = -100, using a different colour from the list for each.
Start โ35Draw a line chart
Draw an x axis and a y axis from the origin at (-150, -100), then plot the sales as dots (50 apart across, 5 times the value up) joined by lines.
Start โ36Capstone: a report table
Write grade(score) (A for 80 or more, B for 70 or more, otherwise C) and print the ranking, highest first, as an aligned table with a header, then the average (2 decimal places) and the name of the top scorer.
Start โPractise the idea
๐ Play Bug Hunter
A Python program prints the wrong answer. Find the one line with the bug, then see the fix and why it was wrong.
FAQ
Cleaning messy data: common questions
I am stuck. What can I do?
Press Hint for a nudge, read the message next to each goal, and compare your code with the lesson text. If you still need it, Show answer reveals a model solution. Try to type it yourself rather than copy it.
Does my work get saved?
Your ticks and XP are saved in this browser, and in your account if you log in. The code you type is not stored on a server.
Start a conversation
Enjoying coding? Meet a teacher.
Tell us the learner's age, country and what they would like to build, and we will suggest a class. A parent or guardian can make the enquiry.
- Tell us the learnerโs age or grade and goals
- Weโll suggest a suitable class or learning path
- Weโll confirm format, timing and fees with a parent or guardian
Play it, don't just read it
Write some code right now
Free games that need no sign-up. Pick one and play for five minutes.
Pick a game
- Bug HunterA Python program prints the wrong answer. Find the one line with theโฆPlay
- Predict the OutputRead a short Python program and choose what it prints. Then watch it runโฆPlay
- Code BuilderThe lines of a Python program are mixed up. Tap them into the rightโฆPlay
- Code JungleWrite real Python to guide Miko the monkey to every banana. 24 levels:โฆPlay