Fall 2024 Quiz 2

← return to practice.dsc10.com


This quiz was administered in-person. It was closed-book and closed-note; students were not allowed to use the DSC 10 Reference Sheet. Students had 20 minutes to work on the quiz.

This quiz covered Lectures 5-10 of the Fall 2024 offering of DSC 10.


The DataFrame uc has information about the number of degrees awarded by each University of California campus, for each of the past six academic years "2018-2019" through "2023-2024". Since there are ten UC campuses and six years of data, there are 60 rows. The columns are "Campus" (str), "Year" (str), and "Degrees" (int).

The first 3 rows of uc are shown here.


Problem 1

Select the correct way to fill in the blank such that the code below evaluates to a DataFrame with a single row for each UC campus, where the "Degrees" column contains the average number of degrees awarded by that campus per academic year (over the past six years).

uc.groupby(______).mean()

Answer: "Campus"


Difficulty: ⭐️⭐️⭐️⭐️

The average score on this problem was 40%.


Problem 2

Fill in the blank so that the expression below evaluates to the number of years (out of the past six years) in which UC San Diego awarded more than 12,000 degrees.

uc[______].shape[0]

Answer: (uc.get("Campus") == "San Diego") & (uc.get("Degrees") > 12000)


Difficulty: ⭐️⭐️⭐️

The average score on this problem was 61%.


Problem 3

Suppose we plot a density histogram showing the distribution of the "Degrees" column in uc, using the argument bins=np.arange(0, uc.get("Degrees").max() + 3000, 2000) .

Suppose there are 12 rows of uc corresponding to campuses and years in which fewer than 2000 degrees were awarded. How tall will the first bar in the histogram be? Give your answer as an exact decimal or simplified fraction.

Answer: 0.0001


Difficulty: ⭐️⭐️⭐️⭐️

The average score on this problem was 33%.


Problem 4


Problem 4.1

Typically, graduation ceremonies happen only at the end of an academic year. For example, students who earn a degree in the 2024-2025 academic year celebrate with a graduation ceremony in 2025.

The function ceremony_year takes as input a string formatted like those in the "Year" column of , and returns an int corresponding to the year of the graduation ceremony for that academic year. For example, ceremony_year("2024-2025") should return 2025. Fill in the return statement of this function below.

Answer: def ceremony_year(academic_year):
                  return int(academic_year.split("-")[1])


Difficulty: ⭐️⭐️⭐️

The average score on this problem was 70%.



Problem 4.2

What does the following expression evaluate to? Write your answer exactly how the output would appear in Python.

uc.get("Year").apply(ceremony_year).min()

Answer: 2019


Difficulty: ⭐️⭐️

The average score on this problem was 87%.



Problem 5

The DataFrame mascots has 10 rows, one for each UC school, and only two columns, "school" and "mascot". Assuming that the entries in the "school" column are formatted exactly how they appear in the "Campus" column of uc, how many rows does the following merged DataFrame have?

uc.merge(mascots, left_on="Campus", right_on="school")

Answer: 60


Difficulty: ⭐️⭐️⭐️

The average score on this problem was 65%.


Problem 6

Define the function puzzle as below.

def puzzle(word):
    if not(len(word) > 2):
        return False
    elif word in "UC San Diego": 
        return True
    else:
        return not("UC" in word)  

Select all the function calls that evaluate to True.

Answer:

  • Option 1: puzzle("UC San")
  • Option 4: puzzle("HDSI")

Difficulty: ⭐️⭐️⭐️

The average score on this problem was 74%.


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