Spring 2025 Quiz 2

← return to practice.dsc10.com


This quiz was administered in-person. It was closed-book; students were not allowed to use the DSC 10 Reference Sheet but were allowed a double-sided sheet of handwritten notes. Students had 20 minutes to work on the quiz.

This quiz covered Lectures 6-9 of the Spring 2025 offering of DSC 10.

⚠️ PDF version available here .


That's the end of the quiz.

The DataFrame ghibli contains information about all 25 films produced by Studio Ghibli, the acclaimed Japanese animation studio. For each film, we have its "Name", "Director", "Budget" and "Revenue" (both in millions of dollars), primary "Genre", and "Runtime" in minutes. ghibli has 25 rows. The first two are shown below.


Problem 1

Lecture 8

Fill in the blanks below to add a new column to ghibli called "TimeString", containing the runtime of each film as a string in hours and minutes. For example, Spirited Away is 125 minutes long, so its value in the "TimeString" column would be "2 hours, 5 minutes".

def change_time(mins):
    hours = ___(a)___
    minutes = ___(b)___
    return str(hours) + " hours, " + str(minutes) + " minutes"
    
ghibli = ghibli.assign(TimeString = ___(c)___)

Answer (a): int(mins / 60)

Solution (a): The number of hours in general can be given by dividing the number of minutes by 60 (since there are 60 minutes per hour). This is where we get mins / 60 from. Then, we convert this number into an integer to ensure that we have a whole number. We do not want a float value here because we are going to calculate the remaining minutes in part (b). This is where int() comes from.


Difficulty: ⭐️⭐️⭐️

The average score on this problem was 73%.

Answer (b): mins % 60

Solution (b): Because we calculated the number of whole hours in the previous part, we are interested in calculating the remaining minutes leftover. We can use the % operator (modulus), which calculates the remainder of a division between two numbers. Like the previous part, we know that there are 60 minutes in an hour. We want to find the remaining minutes that are leftover from this division. This is where we get mins % 60 from.


Difficulty: ⭐️⭐️⭐️

The average score on this problem was 62%.

Answer (c): ghibli.get("Runtime").apply(change_time)

Solution(c): In this question, we want to assign a column called TimeString to our DataFrame. We are told from the problem statement that this column should contain the runtime of each film as a string in hours and minutes. This means that we want to apply our change_time function to our current Runtime column. Then, we can assign this new data to our new TimeString column. To get the RunTime column, we use .get(). To apply the function to every cell in this column, we use .apply(change_time). Notice that we only have to write change_time (the function name). Do not include the parameter(s).


Difficulty: ⭐️⭐️

The average score on this problem was 85%.


Problem 2

Lecture 7

Below is a density histogram showing the distribution of "Runtime", in minutes, for all 25 films in ghibli.


Problem 2.1

How many Studio Ghibli films are at least 90 minutes long?

Answer: 19

Solution: We know that the entire area of this histogram is equal to 1. Instead of calculating the area of each individual bin that is above 90, we can simply calculate the area of the [70, 80) bin and the [80, 90) bins, sum these two areas, and subtract from 1. This will give us the remaining area, which is equivalent to calculating the combined area of all of the bins above 90. We get the area of the [70, 80) bin by multiplying its height and width: 0.008 * 10 = 0.08. We get the area of the [80, 90) bin by multiplying its height and width: 0.016 * 10 = 0.16. Summing these two areas, we get 0.08 + 0.16 = 0.24. Now, we can subtract from 1, getting 1 - 0.24 = 0.76. Since 0.76 is a proportion, we know that 76% of films in our dataset are at least 90 minutes long. We can calculate our final answer now: 0.76 * 25 = 19.


Difficulty: ⭐️⭐️

The average score on this problem was 79%.


Problem 2.2

Imagine we changed our histogram to have just one bin, from 70 to 140 minutes. What would the height of this bin be? Give your answer as an exact fraction or decimal.

Answer: \frac{1}{70}

Solution: Recall that the entire area of our histogram must equal 1. If we only have one bin from 70 to 140 which represents all of our data, the area of this bin must equal 1. We also know the width, which is 140 - 70 = 70. Knowing that the equation for finding the area is area = height * width, we can plug in our values to get 1 = height * 70. Solving for height, we get 1 / 70.


Difficulty: ⭐️⭐️⭐️

The average score on this problem was 58%.



Problem 3

Lecture 9

Using ghibli, write one line of code that outputs a DataFrame describing how many films of each genre each director has directed.

Answer: ghibli.groupby(["Director", "Genre"]).count()

Solution: We want to know how many films are of each genre for each director. The use of the word “each” suggests that we want to use groupby here with the attributes Director and Genre. To do this, we pass an array of columns that we want to group by. this is where ["Director", "Genre"] comes from. Now, our DataFrame has one row for every director-genre combination, which is what we want. We want to know how many films are present in each combination. This means that we want to use .count(), which counts the number of films that are of a specific director-genre combination.


Difficulty: ⭐️⭐️

The average score on this problem was 86%.


Problem 4

Lecture 9

Kate loves Studio Ghibli and she has been recording her viewings of their films in the kate DataFrame, which is shown in full below. Note that kate has repeated rows since Kate watched some films twice.

In ghibli, there are 11 films directed by Hayao Miyazaki and only 2 directed by Hiromasa Yonebayashi.

How many rows are in the DataFrame resulting from ghibli.merge(kate, on="Director")?

Answer: 81

Solution: For every single row (film) that is directed by Hayao Miyazaki in ghibli, it will match with all of the rows (films) in kate that have a Director of “Hayao Miyazaki”. We know that there are 11 rows in ghibli that have a Director attribute of “Hayao Miyazaki”. We know that there are 7 rows in kate that have have the same (Director attribute of “Hayao Miyazaki”). Each of the 11 rows in ghibli will match with all 7 of the rows in kate. With math, we can write this as 11 * 7 = 77. We can now do the same with Hiromasa Yonebayashi films. There are 2 films directed by Hiromasa Yonebayashi in ghibli. In kate, there are 2 films that she has watched that are directed by Hiromasa Yonebayashi. Each of the 2 rows in ghibli will match with all 2 of the rows in kate. With math, we can write this as 2 * 2 = 4. Now, we know the final DataFrame will have 77 + 4 = 81 rows.


Difficulty: ⭐️⭐️⭐️⭐️

The average score on this problem was 46%.


Problem 5

Lecture 6

The scatter plot below shows the budget and revenue (in millions of dollars) for each of the 6 distinct films in kate. Answer each question below, or write “not enough info" if you don’t have enough information to answer.


Problem 5.1

How many of these films had less than 200 million dollars in revenue?

Answer: 4

Solution: Look at the y-axis (Revenue in Millions) and locate the tick mark that represents $200 million. Imagine you drew a line from this tick mark on the left side of the graph to the right side of the graph. There are 4 dots that will be under this line, representing 4 films that had less than $200 million in revenue.


Difficulty: ⭐️

The average score on this problem was 98%.



Problem 5.2

How many of these films earned a revenue more than five times their budget?

Answer: 4

Solution:

Let’s move left to right and analyze each dot along the way. The first dot has a budget of around $19 million. Five times of this is given by the following expression: 19 * 5 = 95. This dot has a revenue of around $275 million, which is much higher than $95 million. We can repeat this process with the rest of the dots. You will notice that the first four dots follow this pattern, but the last two do not. The second-to-last dot has a budget of $30 million. Five times of this is $150 million, but the revenue for this dot is only around $120 million. Similarly, the last dot has a budget of $100 million. Five times of this is $500 million, but the revenue for this dot is only around $170 million.


Difficulty: ⭐️⭐️

The average score on this problem was 85%.



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