Skip to content

Commit

Permalink
q9 edited
Browse files Browse the repository at this point in the history
  • Loading branch information
clairewowo committed Nov 18, 2024
1 parent b873eaa commit 1bd9d7c
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions problems/fa24-midterm/q09.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ fun-sized. Suppose we have an additional DataFrame, `trick`, which is
indexed by `"candy"` and has one column, `"price"`, containing the cost
in dollars of a **single piece** of fun-sized candy, as a `float`.

Suppose that:
Suppose that\:

- `treat` has 200 rows total, and includes 15 distinct types of
candies.
Expand All @@ -14,7 +14,7 @@ Suppose that:
`treat`, plus 10 additional rows that correspond to candies not
represented in `treat`.

Consider the following line of code:
Consider the following line of code\:

trick_or_treat = trick.merge(treat, left_index = True, right_on = "candy")

Expand All @@ -30,9 +30,16 @@ How many rows does `trick_or_treat` have?

# BEGIN SOLUTION

**Answer**: 200
**Answer**\: 200

<average>44</average>
We are told that `trick` has 25 rows\: 15 from candies that are in `treat` and 10 additional candies.
This means that each candy in `trick` appears exactly once because 15+10= 25. In addition, a general
property when merging dataframes is that the number of rows for one shared value between the dataframes is
the product of the number of occurences in either dataframe. For example, if Twix occurs 5 times
in `treat`, the number of times it occurs in `trick_or_treat` is 5 * 1 = 5 (it occurs once in `trick`).
Using this logic, we can determine how many rows are in `trick_or_treat`. Since each number of candies is multipled by one and they sum up to 200, the number of rows will be 200.

<average>39</average>

# END SOLUTION

Expand Down

0 comments on commit 1bd9d7c

Please sign in to comment.