← return to practice.dsc10.com
This quiz was administered in-person. Students were allowed a
double-sided sheet of handwritten notes. Students had 20
minutes to work on the quiz.
This quiz covered Lectures
1-6 of the Winter
2025 offering of DSC 10.
⚠️ PDF version available here .
The DataFrame clubs contains information about all the
student organizations at UCSD. For each club, we have its
"Name", "Category", number of
"Members", "Budget" in dollars,
"Rating" out of 5.0, and whether it is
"Active" represented by either True or
False. The first three rows of clubs are shown below.
Assume that all club names are unique.

The Cheese Club currently has 50 members. Each quarter, the number of people who will join the club is the value of the Python expression below.
3 * ((4 * 20 / 5 * 2 + 4) ** 0.5 - 2 ** 2)
How many members will the club have after 3 quarters?
56
68
74
82
None of these.
Answer: 68
Work from the innermost parentheses out, following order of operations:
4 * 20 / 5 * 2 runs left to right, since *
and / have equal precedence: 80 /
5 = 16, then 16 \cdot 2 =
32.32 + 4 = 3636 ** 0.5 = 6.0. Raising to the 0.5 power is a square
root.2 ** 2 = 4, so the parentheses give 6.0 - 4 = 2.0.3 * 2.0 = 6.0 new members per quarter.After 3 quarters:
50 + 3 \cdot 6 = 68
The average score on this problem was 65%.
How many unique data types exist in the clubs
DataFrame?
2
3
4
5
6
None of these.
Answer: 4
Look at the kind of value stored in each column:
"Name" and "Category" hold text:
str"Members" and "Budget" hold whole numbers:
int"Rating" is a decimal out of 5.0:
float"Active" is True/False:
boolThat’s 4 unique types: str, int, float, and bool.
The average score on this problem was 61%.
Suppose we run the following code.
clubs_and_ratings = ["Cheese Club".upper(), str(int(4.6)), "Painting Club".title(), 3.7 - 1]
a = np.array(clubs_and_ratings)What do a[0], a[1], a[2], and
a[3] evaluate to?
Answer:
a[0]: "CHEESE CLUB"
a[1]: "4"
a[2]: "Painting Club"
a[3]: "2.7"
First, evaluate each element of the list:
"Cheese Club".upper() → "CHEESE CLUB"int(4.6) truncates to 4 (it doesn’t
round), and str(4) → "4""Painting Club".title() capitalizes the first letter of
each word, which it already does → "Painting Club"3.7 - 1 → 2.7, a floatThe key step is np.array(...). Every element of an array
must have the same type, so when a list mixes strings
and numbers, NumPy converts everything to strings. That’s why
a[3] is the string "2.7", not the float
2.7.
The average score on this problem was 75%.
One of the clubs in the clubs DataFrame is the
"Surf Club". Without querying, write an
expression that evaluates to the rating of this club.
Answer:
clubs.set_index("Name").get("Rating").loc["Surf Club"]
Club names are unique, so we can make "Name" the index
with .set_index("Name"). Then .get("Rating")
pulls out the ratings as a Series, indexed by club name.
.loc["Surf Club"] grabs the value whose index
label is "Surf Club". The order
.loc["Surf Club"].get("Rating") also works, as long as
set_index comes first.
The average score on this problem was 62%.
Now, using a query, write an expression that evaluates to the rating
of the "Surf Club".
Answer:
clubs[clubs.get("Name") == "Surf Club"].get("Rating").iloc[0]
clubs.get("Name") == "Surf Club" makes a Boolean Series
that’s True only for the Surf Club row.clubs[...] keeps just the rows where it’s
True. That’s a DataFrame with one row..get("Rating") gives a Series with one
value. It’s still a Series, not a number..iloc[0] pulls out the value at position 0. We use
.iloc (position) rather than .loc (label)
because a query keeps the original index labels, so the Surf Club row’s
label isn’t necessarily 0.
The average score on this problem was 48%.
Fill in the blanks so the expression below evaluates to the name of
the category (e.g. "Social") with the largest number of
members, on average.
(clubs.groupby(__(a)__).__(b)__.sort_values(by="Members", ascending=__(c)__).__(d)__)Answer:
(a): "Category"
(b): mean()
(c): False
(d): index[0]
"Category" and aggregate
with .mean()."Members" with
ascending=False puts the category with the largest average
at the top.groupby, the category
names become the index, not a column. So
.index[0] gives the first label in the sorted index, which
is the category name we want.
The average score on this problem was 59%.
In each category, what is the largest budget for a club? Write one line of code that would produce an appropriate data visualization to answer this question.
Answer:
clubs.groupby("Category").max().plot(kind= "bar", y= "Budget")
There are two steps:
.groupby("Category").max() finds the largest value of each
column within each category. The "Budget" column of the
result is the largest budget per category.kind="barh" is also fine). y="Budget" says
which column to plot. The category names are in the index, so they
automatically label the bars.
The average score on this problem was 38%.
The Data Science Student Society has a $500 budget,
which they will use only to buy food for their 4 meetings this quarter.
Each time they have a meeting, they will use exactly half of their
remaining budget on food. For example, the first meeting’s food cost
will be $250 and the next meeting’s food cost will be
$125. Use np.arange(), together with
arithmetic operations, to assign food_costs to an array
containing the food cost for each of the 4 meetings. Do
not use np.array().
food_costs =
Answer: 500 * 0.5 ** np.arange(1,5) or
500/2 ** np.arange(1,5)
Each meeting costs half of the previous one, so the costs are:
500 \cdot 0.5^1,\ 500 \cdot 0.5^2,\ 500 \cdot 0.5^3,\ 500 \cdot 0.5^4 = 250,\ 125,\ 62.5,\ 31.25
The exponents run from 1 to 4, which is exactly
np.arange(1, 5). The stop value isn’t included. Arithmetic
on an array is applied to every element, so
0.5 ** np.arange(1, 5) gives
[0.5, 0.25, 0.125, 0.0625], and multiplying by 500 gives
the four costs.
This also depends on precedence: ** runs before
* and /. So 500 * 0.5 ** ...
raises 0.5 to each power first and then multiplies, which is what we
want.
The average score on this problem was 11%.