Final exam
Python for Data Science
Before you start
- 20 questions, drawn at random from a pool of 33.
- Pass mark: 70%. Your final score is 30% practice + 70% exam.
- No time limit, but finish within 3 hours. You can move between questions before you submit.
- Failed? Review the lessons and try again: every attempt gets a new set of questions.
Question 1 of 20Put in order
Order these stages of a data project.
Drag the items, or use the arrow buttons, to put them in order.
- Clean types, missing values and duplicates
- Explore with summaries and charts
- Present findings
- Load the data
- Model and evaluate if needed
- Agree on the question and how success is measured
Question 2 of 20Choose one
Before sharing results from a Jupyter notebook, which step best confirms they are reproducible?
Question 3 of 20Match the pairs
Match each library to its main job.
Tap an answer, then tap the place where it belongs (or drag it there).
- NumPy
- pandas
- seaborn
- scikit-learn
Question 4 of 20Work it out
What does this Python expression return? len({c for c in ["NY", "LA", "NY", "SF", "LA"]})
Question 5 of 20What would you do?
What would you do?
What does this code print?
orders = [{"total": 120}, {"total": 80}, {"total": 200}]
big = [o["total"] for o in orders if o["total"] > 100]
print(sum(big))Question 6 of 20True or false
For a Python list, [1, 2] + [3, 4] gives [4, 6].
Question 7 of 20Work it out
An array has shape (200, 5). How many elements does it contain?
Question 8 of 20Choose one
What is the shape of np.arange(24).reshape(4, -1)?
Question 9 of 20Work it out
For sales = np.array([[3, 5, 2], [4, 1, 6]]), what is the first value of sales.sum(axis=1)?
Question 10 of 20Sort into groups
Which shape pairs broadcast together?
Tap an item, then tap its group (or drag it there).
Question 11 of 20Spot the mistake
Click the line that will raise an error when selecting values greater than 5 and less than 10 from a NumPy array a.
Question 12 of 20Work it out
A DataFrame has the default integer index 0 to 99. How many rows does df.iloc[10:20] return?
Question 13 of 20Choose one
A price column shows dtype object after loading. What is the most likely cause?
Question 14 of 20Fill in the blanks
Fill in the blanks
To keep rows where region is "North" or "South", write df[df["region"].(["North", "South"])].
Question 15 of 20What would you do?
What would you do?
Kim runs df.sort_values("score", ascending=False) and then df.head(), but the rows still appear unsorted. What happened?
Question 16 of 20Work it out
Orders: (East, 40), (West, 10), (East, 20), (West, 30), (East, 30). What is df.groupby("region")["amount"].sum() for East?
Question 17 of 20Match the pairs
Match each task to the pandas tool.
Tap an answer, then tap the place where it belongs (or drag it there).
- Count how often each category occurs
- Compute mean, min and max per group in one call
- Add each row's group total as a new column
- Show regions down the side and months across the top
Question 18 of 20True or false
In a group with 6 rows where 2 values of amount are missing, count returns 4 and size returns 6.
Question 19 of 20Work it out
A products table has unique product IDs. A sales table has 8,000 rows, of which 120 have product IDs missing from products. How many rows does sales.merge(products, on="product_id", how="left") return?
Question 20 of 20What would you do?
What would you do?
A left merge of 5,000 orders onto a customers lookup table returns 5,260 rows. What should the analyst check first?
Question 21 of 20Work it out
A wide table has 40 rows (one per city) with a city column and 7 weekday columns. How many rows does it have after melting the weekday columns into long format?
Question 22 of 20Select all that apply
Which are valid ways to handle missing values? Select all that apply.
Select all that apply.
Question 23 of 20Work it out
A column contains 6, NaN, 9 and 15. What does pandas return for .mean()?
Question 24 of 20Sort into groups
Choose the best fix for each problem.
Tap an item, then tap its group (or drag it there).
Question 25 of 20Work it out
Household incomes (in $k) are 38, 41, 45, 52 and 240. What is the mean minus the median, in $k?
Question 26 of 20Work it out
Q1 is 40 and Q3 is 60. What is the upper fence for outliers under the 1.5 × IQR rule?
Question 27 of 20Work it out
Test scores have mean 70 and standard deviation 5. What is the z-score of a score of 82?
Question 28 of 20True or false
A Pearson correlation near 0 proves there is no relationship of any kind between two variables.
Question 29 of 20Match the pairs
Match each question to the chart that answers it best.
Tap an answer, then tap the place where it belongs (or drag it there).
- How did monthly revenue change over three years?
- How are order values distributed?
- Is ad spend related to sales across 200 stores?
- Which five products sold the most units?
Question 30 of 20Choose one
A bar chart compares two values of 81% and 84% with a y-axis that starts at 80%. What is the main problem?
Question 31 of 20Work it out
A model predicts 30, 42 and 18 for actual values 33, 40 and 18. What is the mean absolute error?
Question 32 of 20What would you do?
What would you do?
A churn model scores 99% accuracy in testing but performs poorly after launch. Investigation shows a feature called account_closed_reason, filled in only after a customer leaves. What went wrong?
Question 33 of 20Choose one