Select a Single Column
You have a DataFrame df with employee data. Select only the name column and store it in result. Available Data:...
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.
You have a DataFrame df with employee data. Select only the name column and store it in result. Available Data:...
Select the name and salary columns from the employee DataFrame. Available Data: DataFrame df with columns: name,...
Filter the employee DataFrame to find all employees in the Engineering department. Available Data: DataFrame df with...
Find employees who are in Engineering AND earn more than $100,000. Available Data: DataFrame df with columns: name,...
Sort the employee DataFrame by salary in descending order. Available Data: DataFrame df with columns: name, department,...
Get the top 3 highest-paid employees from the DataFrame. Available Data: DataFrame df with columns: name, department,...
Find the number of rows in the employee DataFrame. Available Data: DataFrame df with columns: name, department, salary,...
Find all unique departments in the employee DataFrame. Available Data: DataFrame df with columns: name, department,...
Add a new column called bonus to the employee DataFrame. The bonus should be 10% of each employee's salary. Available...
Count how many employees are in each department. Available Data: DataFrame df with columns: name, department, salary,...
Find the mean salary across all employees. Available Data: DataFrame df with columns: name, department, salary, age,...
Rename the columns of the employee DataFrame: name to employee_name and salary to annual_salary. Available Data:...
Set the name column as the index of the DataFrame. Available Data: DataFrame df with columns: name, department, salary,...
Find employees who work in either Engineering or HR. Available Data: DataFrame df with columns: name, department,...
Create a DataFrame with the following data: fruitquantityprice Apple101.5 Banana250.5 Cherry153.0 Requirements: Create...
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.