Day 20: Revision Test: Python + Pandas
✅ Today you will learn
- Solve 15 tasks without looking at solutions
- Score yourself honestly (1 point each)
- Revise weak topics from Days 10–19
- Practise the style of data-analyst take-home tests
🏢 In the real world
Many companies send a 2-hour “take-home” test before the interview: a CSV and ten questions. This page is that test. Set a timer, open a notebook and try each task first – then open the solution.
How to use this test
- Download the datasets (Download button in the sidebar).
- Spend at most 10 minutes per task.
- Write your answer, then open “Show solution”.
- Give yourself 1 point for a correct result, ½ if close.
- 12+ = job-ready, 8–11 = revise weak days, below 8 = repeat Days 10–19.
| Tasks | Topic | Revise |
|---|---|---|
| 1–3 | Reading, selecting, filtering | Days 11–12 |
| 4–6 | GroupBy, pivot, crosstab | Day 13 |
| 7–8 | Merge | Day 14 |
| 9–10 | Cleaning | Day 15 |
| 11–12 | Dates and text | Day 16 |
| 13–15 | Features and EDA | Days 17–19 |
Import once at the top: import pandas as pd, numpy as np. Read each file once into a variable and use .copy() before changing it.
🏅 Job skills unlocked today
Practice tasks
🏋️ Practice – do it yourself
sales_data.csv came from the South region with quantity ≥ 3?Show solution
import pandas as pd
s = pd.read_csv("sales_data.csv")
print(len(s[(s["region"] == "South") & (s["quantity"] >= 3)]))Show solution
import pandas as pd
s = pd.read_csv("sales_data.csv")
print(s[s["category"] == "Fashion"].nlargest(5, "unit_price")[["order_id", "product", "unit_price"]].to_string(index=False))Show solution
import pandas as pd
s = pd.read_csv("sales_data.csv")
print((s.groupby("city")["payment_mode"].apply(lambda p: (p == "UPI").mean()) * 100).round(1).sort_values(ascending=False))Show solution
import pandas as pd
s = pd.read_csv("sales_data.csv", parse_dates=["order_date"])
s["revenue"] = s["quantity"] * s["unit_price"] * (1 - s["discount"])
print((s.pivot_table(index="category", columns=s["order_date"].dt.quarter, values="revenue", aggfunc="sum") / 1e5).round(2))Show solution
import pandas as pd
t = pd.read_csv("telecom_churn.csv")
t["churned"] = t["churn"].eq("Yes")
r = t.groupby("payment_method").agg(customers=("customer_id", "count"), churn_rate=("churned", "mean"))
r["churn_rate"] = (r["churn_rate"] * 100).round(1)
print(r.sort_values("churn_rate", ascending=False))Show solution
import pandas as pd
t = pd.read_csv("telecom_churn.csv")
print((pd.crosstab(t["tech_support"], t["churn"], normalize="index") * 100).round(1))
print("Customers without tech support churn far more – offer it free for 3 months.")Show solution
import pandas as pd
e = pd.read_csv("employees.csv"); d = pd.read_csv("departments.csv")
m = e.merge(d, on="dept_id", how="left")
print(m["dept_name"].isna().sum())Show solution
import pandas as pd
e = pd.read_csv("employees.csv"); d = pd.read_csv("departments.csv")
print(e.merge(d, on="dept_id").groupby("location")["salary"].sum().sort_values(ascending=False))sales_dirty.csv, how many rows remain after removing exact duplicates and rows with unit_price ≤ 0?Show solution
import pandas as pd
d = pd.read_csv("sales_dirty.csv").drop_duplicates()
print(len(d[d["unit_price"] > 0]))sales_dirty.csv, standardise city names and print the number of unique cities before and after.Show solution
import pandas as pd
d = pd.read_csv("sales_dirty.csv")
print(d["city"].nunique(), "->", d["city"].str.strip().str.title().nunique())Show solution
import pandas as pd
w = pd.read_csv("delhi_weather.csv", parse_dates=["date"])
nov = w[w["date"].dt.month == 11].groupby(w["date"].dt.year)["aqi"].mean().round(1)
print(nov); print("Highest:", nov.idxmax())Show solution
import pandas as pd
r = pd.read_csv("product_reviews.csv")
m = r[r["review"].str.contains("money", case=False)]
print(len(m), "reviews |", round((m["sentiment"] == "negative").mean() * 100, 1), "% negative")Show solution
import pandas as pd
st = pd.read_csv("students_performance.csv")
st["study_band"] = pd.qcut(st["study_hours"], 4, labels=["Low", "Mid-low", "Mid-high", "High"])
print(st.groupby("study_band", observed=True)["average"].mean().round(1))Show solution
import pandas as pd
l = pd.read_csv("loan_applications.csv")
print(l.columns.tolist())
print((l.groupby("employment")["approved"].mean() * 100).round(1).sort_values(ascending=False))Show solution
import pandas as pd
h = pd.read_csv("house_prices.csv")
v = (h["area_sqft"] / h["price_lakh"]).groupby(h["city"]).mean().round(1).sort_values(ascending=False)
print(v)
print(f"A buyer gets about {v.iloc[0]:.0f} sqft per lakh in {v.index[0]} vs {v.iloc[-1]:.0f} in {v.index[-1]}.")Quick quiz
🧠 Quick Quiz – test yourself
Interview corner
💼 Interview Corner
You get a 5 GB CSV that does not fit in memory. What do you do?
Read only needed columns (usecols), set smaller dtypes (category, int32), read in chunks (chunksize) and aggregate each chunk, or use a database / tools like DuckDB or Polars.
How do you make your pandas analysis reproducible?
Never edit raw files, put cleaning in functions, fix random seeds, record package versions (requirements.txt), and keep the notebook running top-to-bottom without errors.
Summary
- You have finished the pandas block – the core skill of every data job.
- Score 12+? Move on to visualisation. Lower? Revise the listed days.
- Keep your solutions – they become portfolio snippets.
Week 4 starts! Day 21: Matplotlib – line, bar, scatter, histograms and subplots that look professional.
