Fall 2026 Quiz 2

Appearance

← return to practice.dsc10.com


Instructor(s): Peter Chi, Janine Tiefenbruck

This quiz was administered in-person. Students were allowed one page of double-sided handwritten notes; students were not allowed to use the DSC 10 Reference Sheet. Students had 20 minutes to work on the quiz.

This quiz covered Lectures 6-9 of the Fall 2026 offering of DSC 10.

⚠️ PDF version available here .


That's the end of the quiz.

Sujal, Austin, and Rishika cleared their schedules on October 3rd, only to realize that San Diego had become an oven that day, with temperatures crossing 100°F.

The DataFrame oct3 contains information on 10 various San Diego locations on that date. It is indexed by "Location". Its columns are "Temp" (int), the high temperature for the day; "Elevation" (int), the elevation in feet; and "Coastal" (bool), whether the location is coastal.

The oct3 DataFrame with Location as the index and Temp, Elevation, and Coastal columns for all 10 San Diego locations.

Assume we have already run import babypandas as bpd and import numpy as np.

If your answer is a string, put it in quotes. If your answer is a float, include a decimal point. No calculators and no computers were allowed.


Problem 1

Lecture 8

Sujal wants to see whether locations at higher elevations are cooler. Assume that he has already defined a function called elevation_category, which takes in an integer elevation in feet and returns "low" when the elevation is at most 100, "medium" when it is greater than 100 and at most 400, and "high" otherwise.


Problem 1.1

Write one line of code to create a DataFrame oct3_cat, which contains every column in oct3, plus a new column named "Elevation_Category" with the appropriate categorical label, "low", "medium", or "high".

Answer:

oct3_cat = oct3.assign(Elevation_Category=oct3.get("Elevation").apply(elevation_category))

We want to add a new column called Elevation_Category to the oct3 DataFrame. This was covered in the functions and applying lecture.

  • .get("Elevation") retrieves the Elevation column as a Series.
  • .apply(elevation_category) applies the given function to every elevation value, categorizing each location as "low", "medium", or "high".
  • .assign(Elevation_Category=...) adds the resulting Series as a new column called Elevation_Category, while keeping all existing columns.

Finally, we assign the resulting DataFrame to oct3_cat.


Difficulty: ⭐️⭐️

The average score on this problem was 81%.


Problem 1.2

Which bar chart is produced by the following code? Bar heights are labeled for your convenience.

(oct3_cat
 .drop(columns=["Coastal"])
 .take(2 * np.arange(3) + 1)
 .take(np.arange(2))
 .groupby("Elevation_Category")
 .mean()
 .plot(kind="bar", y="Temp"))
Four candidate bar charts labeled A through D. A and B plot temperature by numeric elevation; C and D plot temperature by elevation category.

Answer: D.

Explanation Video

We analyze the code step by step.

Step 1: .drop(columns=["Coastal"])

Removes the Coastal column from the DataFrame.

Step 2: .take(2 * np.arange(3) + 1)

First, np.arange(3) produces:

np.array([0, 1, 2])

We perform element-wise multiplication by 2:

np.array([0, 2, 4])

Then, we add 1 to every element:

np.array([1, 3, 5])

Therefore, .take([1, 3, 5]) selects the rows at positions 1, 3, and 5 (using zero-based indexing).

These correspond to:

Location Temp Elevation Elevation_Category
UCSD 94 390 medium
Mira Mesa 104 440 high
Downtown 97 50 low

Step 3: .take(np.arange(2))

np.arange(2) produces:

np.array([0, 1])

This selects the first two rows of the current DataFrame, not the original DataFrame.

We are left with:

Location Temp Elevation Elevation_Category
UCSD 94 390 medium
Mira Mesa 104 440 high

Step 4: .groupby("Elevation_Category")

Groups the remaining rows according to their elevation category.

  • UCSD belongs to the "medium" category.
  • Mira Mesa belongs to the "high" category.

Step 5: .mean()

Calculates the average of the numerical columns for each group.

Since each category contains only one location, the average temperature is simply that location’s temperature.

  • high: 104
  • medium: 94

Step 6: .plot(kind="bar", y="Temp")

Creates a bar chart displaying the average temperature for each elevation category.

The bars are labeled "high" and "medium", with heights 104 and 94, respectively.

Therefore, Option D is correct.


Difficulty: ⭐️⭐️⭐️

The average score on this problem was 64%.



Problem 2

Lecture 9

For this question, assume oct3_cat was correctly created in Question 1.


Problem 2.1

Write one line of code that evaluates to a DataFrame containing the average temperature associated with each combination of values in the "Elevation_Category" and "Coastal" columns.

Answer:

oct3_cat.groupby(["Coastal", "Elevation_Category"]).mean().get(["Temp"])

Explanation Video


Difficulty: ⭐️⭐️

The average score on this problem was 82%.


Problem 2.2

Determine the output of the code cell below.

legend = bpd.DataFrame().assign(
         Elevation_Category=["low", "medium", "high"],
         Color=["yellow", "orange", "red"])
oct3_cat.merge(legend, on="Elevation_Category").shape[0]

Answer: 10

Explanation Video

The merge matches rows from oct3_cat with rows from legend based on their Elevation_Category.

Since legend contains exactly one row for each category ("low", "medium", and "high"), every row in oct3_cat matches exactly one row in legend.

Therefore, the merged DataFrame has the same number of rows as oct3_cat, which is 10.

Diagram of the merge in 2(b): each of the 10 rows of oct3_cat matches the one legend row with the same Elevation_Category (low to yellow, medium to orange, high to red), giving 10 merged rows.

Difficulty: ⭐️⭐️⭐️

The average score on this problem was 70%.


Problem 2.3

Determine the output of the code cell below.

legend2 = bpd.DataFrame().assign(
         Elevation_Category=["low", "medium", "medium", "high"],
         Color=["yellow", "orange", "red", "maroon"])
oct3_cat.merge(legend2, on="Elevation_Category").shape[0]

Answer: 14

Answer: 14

Explanation Video

Unlike Q2(b), legend2 contains two rows with "medium" as the Elevation_Category.

When merging, each "medium" location in oct3_cat matches both "medium" rows in legend2, producing two rows in the merged DataFrame.

There are: - 3 "low" locations, each matching once → 3 rows - 4 "medium" locations, each matching twice → 8 rows - 3 "high" locations, each matching once → 3 rows

Therefore, the merged DataFrame contains 3 + 8 + 3 = 14 rows.

Diagram of the merge in 2(c): legend2 has two medium rows (orange and red), so each of the 4 medium locations matches twice while the 6 low and high locations match once, giving 6 times 1 plus 4 times 2, or 14 merged rows.

Difficulty: ⭐️⭐️⭐️

The average score on this problem was 64%.



Problem 3

Lecture 7


Problem 3.1

Rishika makes a density histogram of the 10 values in the "Temp" column of oct3, shown above. She uses the argument bins = np.arange(90, 110, 5). What is the height of the tallest bar?

Answer: 0.08

Explanation Video

For a density histogram, the height of each bar is calculated using:

\text{Height} = \frac{\text{Number of values in bin}}{\text{Total values} \times \text{Bin width}}

The bins are defined by np.arange(90, 110, 5), so each bin has a width of 5.

Bin Temperatures Count
[90, 95) 90, 91, 94 3
[95, 100) 97, 98, 99 3
[100, 105] 103, 104, 104, 105 4

The last bin includes 105 because the rightmost edge of the histogram is inclusive.

The tallest bar contains 4 out of 10 values.

\text{Height} = \frac{4}{10 \times 5} = \boxed{0.08}


Difficulty: ⭐️⭐️⭐️⭐️⭐️

The average score on this problem was 29%.


Problem 3.2

Rishika then obtains a larger DataFrame of 200 locations. A density histogram of temperatures from this larger DataFrame of 200 locations has bins and heights given below. Assume all locations’ temperatures fall between 80°F and 110°F, inclusive.

Bin Height of Bar
[80,90) 0.02
[90,95) 0.04
[95,100) 0.06
[100,110] X

What is the value of X?

Answer: 0.03

Explanation Video

In a density histogram, the total area of all bars must equal 1.

We calculate each bar’s area using:

\text{Area} = \text{Height} \times \text{Width}

For the first three bins:

  • [80, 90): 0.02 \times 10 = 0.2
  • [90, 95): 0.04 \times 5 = 0.2
  • [95, 100): 0.06 \times 5 = 0.3

The total area of these three bars is:

0.2 + 0.2 + 0.3 = 0.7

Therefore, the remaining bar must have an area of:

1 - 0.7 = 0.3

Since the final bin has a width of 10:

X \times 10 = 0.3

\boxed{X = 0.03}


Difficulty: ⭐️⭐️⭐️

The average score on this problem was 66%.


Problem 3.3

How many of the 200 locations have a "Temp" in [90,100)?

Answer: 100

Explanation Video

We want to determine how many of the 200 locations have temperatures in the interval [90, 100).

This interval includes two histogram bins:

  • [90, 95): 0.04 \times 5 = 0.2
  • [95, 100): 0.06 \times 5 = 0.3

In a density histogram, the area of a bar represents the proportion of observations in that interval.

Therefore, the proportion of locations with temperatures in [90, 100) is:

0.2 + 0.3 = 0.5

Multiplying by the total number of locations:

0.5 \times 200 = \boxed{100 \text{ locations}}


Difficulty: ⭐️⭐️⭐️

The average score on this problem was 61%.



👋 Feedback: Find an error? Still confused? Have a suggestion? Let us know here.