Skip to content

Commit

Permalink
Update q10.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Sophie-WZR authored Nov 20, 2024
1 parent 4757fe2 commit 347a264
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion problems/fa24-midterm/q10.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,25 @@ that houses spent on Halloween candy, in dollars.

- (c): `sum()`

**(a): `tot.get("price") * tot.get("how_many")`**

- `tot.get("price")` retrieves the cost of a single piece of candy.
- `tot.get("how_many")` retrieves the number of pieces of candy given out.
- Multiplying these two columns calculates the total amount spent on candy for each row in the dataset.
- This step creates a new column `total_spent` that represents the total money spent for each type of candy at a given house.


**(b): "address"**

- The data is grouped by the `"address"` column, which uniquely identifies each house. This ensures that all records associated with a single house are aggregated together.

**(c): `sum()`**

- After grouping by `"address"`, the `.sum()` operation aggregates the total amount of money spent on candy for each house. This sums up all `total_spent` values for records belonging to the same house.

Final Output: The `total` DataFrame will have one row for each house, with the column `total_spent` representing the total money spent on Halloween candy. Finally, the `total.plot` command creates a histogram of the `total_spent` values to visualize the distribution of spending across houses.


<average>65</average>

# END SOLUTION
Expand Down Expand Up @@ -60,6 +79,12 @@ houses?

**Answer**: `[20, 30)` and `[30, 40)`

- The histogram shows that the bins `[20, 30)` and `[30, 40)` have the two tallest bars, with heights of 0.020 and 0.030, respectively.
- Each bar's height represents the density of data in that range (proportion of houses divided by bin width). Since the bin width is 10, we can multiply the height by 10 to calculate the proportion of data in each bin:
- `[20, 30)` contributes $0.020 \times 10 = 0.2$ or $20\%$ of the houses.
- `[30, 40)` contributes $0.030 \times 10 = 0.3$ or $30\%$ of the houses.
- Together, these two bins account for $20\% + 30\% = 50\%$ of the houses.

<average>83</average>

# END SOLUTION
Expand All @@ -76,6 +101,17 @@ Approximate the height of the tallest bar in this new histogram. If this is not

**Answer**: 0.025

- With the new bin width of 20, the histogram combines adjacent bins from the original histogram. The new bins become `[0, 20)`,`[20, 40)`,`[40, 60)`,`[60, 80)`. The bin `[20, 40)` merges the original bins `[20, 30)` and `[30, 40)` and would be the bin with the highest bar in the new histogram.
- To find the total proportion of data in `[20, 40)`:
- From the original histogram:
- `[20, 30)` contributes $0.020 \times 10 = 0.2$ (20%).
- `[30, 40)` contributes $0.030 \times 10 = 0.3$ (30%).
- Total for `[20, 40)` is $0.2 + 0.3 = 0.5$ or $50\%$.
- The new bin width is 20, so the height of the bar is calculated as:
Height = $\frac{\text{Proportion}}{\text{Bin Width}}$ = $\frac{0.5}{20}$ = 0.025\
- Therefore, the tallest bar in the new histogram has a height of 0.025.


<average>38</average>

# END SOLUTION
Expand All @@ -93,10 +129,14 @@ of the tallest bar in this new histogram. If this is not possible, write "Not po

**Answer**: Not possible to determine.

- In the original histogram, the bins are 10 units wide (e.g., `[20, 30)`). When switching to 5-unit bins (e.g., `[20, 25)`, `[25, 30)`), we need to know the distribution of data within the original 10-unit bins to calculate the new bar heights.
- The histogram does not provide this detailed information. For example, we cannot determine whether the data in `[20, 30)` is evenly distributed between `[20, 25)` and `[25, 30)` or concentrated in one of the sub-bins.
- Without this additional information, it is impossible to approximate the height of the tallest bar accurately.

<average>70</average>

# END SOLUTION

# END SUBPROB

# END PROB
# END PROB

0 comments on commit 347a264

Please sign in to comment.