Create a Pivot Table
Create a pivot table showing total quantity sold per product in each region. Available Data: DataFrame df with columns:...
Select, group, merge and derive columns on a table in Python, without loops.
A pandas DataFrame is a labelled, two-dimensional table in Python, and most analysis with it comes down to four moves: select the rows and columns you need, group and aggregate them, merge in another table, and derive new columns without looping. Doing that vectorised, with whole-column operations instead of a Python for loop, is what keeps the code both short and fast. These questions run real pandas in the browser against seeded DataFrames, so the output you check is the actual frame.
Create a pivot table showing total quantity sold per product in each region. Available Data: DataFrame df with columns:...
Calculate the total revenue (quantity * price) for each product. Available Data: DataFrame df with columns: date,...
Create a summary showing each customer's total orders, total amount, and average amount. Available Data: DataFrame...
Create a cross-tabulation showing the count of employees per department and city. Available Data: DataFrame df with...
Add a column dept_avg_salary showing the average salary of each employee's department. Available Data: DataFrame df...
Convert all employee names to uppercase. Available Data: DataFrame df with columns: name, department, salary, age, city...
Find all employees whose names start with the letter 'A' or 'E'. Available Data: DataFrame df with columns: name,...
Given a DataFrame with full names, extract just the first name. Available Data: DataFrame df with a full_name column...
Convert the date column from strings to datetime objects and extract the month. Available Data: DataFrame df with...
Calculate total quantity sold per month. Available Data: DataFrame df with columns: date, product, quantity, price,...
Find the highest-paid employee in each department. Available Data: DataFrame df with columns: name, department, salary,...
Add a salary_percentile column showing each employee's percentile rank within the company. Available Data: DataFrame df...
Calculate each student's average score across all subjects and assign a letter grade. Available Data: DataFrame df with...
Merge orders with customers and find the total spending per customer for completed orders only. Sort by total spending...
Create a comprehensive sales report DataFrame showing per-product metrics. Available Data: DataFrame df with columns:...
FAQ
Short answers to what people get stuck on most. Tap a question to expand it.
Aggregations skip NaN by default, so a group still returns a total from its non-missing values.
df.groupby("city")["sales"].sum() # all-NaN group -> 0.0
df.groupby("city")["sales"].sum(min_count=1) # all-NaN group -> NaNloc selects by label, iloc selects by integer position.
df.loc[df["sales"] > 100, "city"] # label + boolean mask
df.iloc[0:2, 0] # first two rows, first columnUse merge, which works like a SQL join. Choose how: inner, left, right or outer.
orders.merge(
customers,
on="customer_id",
how="left",
validate="many_to_one",
)Track your streak & earn XP
Sign up free to unlock your progress dashboard, daily streaks, and leaderboard ranking.
10 role-based tests for Data Analysts, SQL Developers & Data Engineers with instant scorecards.