Chapter 19: Pandas Quiz

Pandas Quiz — designed like we are in a classroom or a 1-on-1 mentoring session.

The goal is not to get everything right on the first try. The goal is to see what you already understand well, what feels a bit shaky, and what we should practice more together.

I prepared three levels:

  • Level 1 — fundamental concepts almost everyone needs to be comfortable with
  • Level 2 — typical day-to-day tasks in real projects
  • Level 3 — slightly trickier / more realistic situations

For each question you get:

  • clear task
  • small ready-to-use dataset
  • space to think / write your answer
  • after you try → detailed solution + explanation + common mistakes people make

Instructions

  1. Copy the dataset into your notebook / online editor
  2. Try to write the code yourself first — even if it’s not perfect
  3. Only look at the solution after you have attempted it
  4. After finishing some questions, come back and tell me:
    • which questions felt easy
    • which ones were difficult / surprising
    • where you got stuck or made mistakes

Let’s begin!

Level 1 – Core foundations

Q1. Selection + filtering + sorting Select only people older than 25 who live in Pune or Mumbai. Show only columns: name, city, salary Sort them by salary descending.

Python

Q2. Creating a new column with condition Create column bonus_pct:

  • 12% if salary > 100_000
  • 8% otherwise

Then create bonus_amount = salary × bonus_pct Show both new columns rounded to nearest whole number.

Q3. Simple aggregation question What is the average salary? How many people earn more than this average? Show their names and salaries.

Q4. Value counts with percentage Show how many people are in each city — both as count and as percentage (1 decimal place).

Level 2 – Everyday realistic tasks

Q5. Groupby + multiple aggregations Group by city and show:

  • number of employees (count)
  • average salary
  • highest salary
  • percentage of people earning > 100_000

Round numbers appropriately.

Q6. Rank within group Create column rank_in_city — salary rank within each city (1 = highest salary in that city)

Show name, city, salary, rank_in_city Sort by city and then by rank.

Q7. Categorizing with conditions Create column level:

  • “Senior” if salary ≥ 120_000
  • “Mid” if salary ≥ 90_000
  • “Junior” otherwise

Show how many people in each level (value_counts)

Q8. Top N per group Show the top 2 highest earners in each city Include: name, city, salary (If a city has fewer than 2 people — show all)

Level 3 – Slightly more realistic / tricky

Q9. Filling missing values with group median Make two salaries missing:

Python

Fill missing salaries with the median salary of their own city. If the city has no valid salaries → use overall median.

Q10. Conditional filtering with group stats Show people who earn more than both:

  • their city’s average salary
  • the overall company average

Show: name, city, salary, city_avg, overall_avg

Q11. Nice summary table Create a table like this (you can use groupby + agg + round):

text

Q12. Merge + filter You receive this additional table:

Python

Left-join it to the main DataFrame on city. Then show only employees whose manager has been in position for less than 3 years (as of 2025).

How to make the most of this quiz

  1. Do not look at solutions until you have tried
  2. Write code even if you are not 100% sure — guessing is learning
  3. After 4–6 questions, come back and tell me:
    • which ones were comfortable
    • which ones felt difficult / confusing
    • any error messages you got
    • what surprised you

Then we can:

  • explain the tricky ones in more depth
  • give follow-up exercises on weak spots
  • move to next topic with stronger foundation

Which questions do you want to start with? Or would you like me to give solutions one by one after you try?

You can also say:

  • “I tried Q1–Q4, here is what I got…”
  • “Q9 looks hard — can you explain first?”
  • “Give me solutions for level 1 only”

Just tell me how you want to proceed — we’ll go at your pace. 😊

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *