diff --git a/docs/sp24-midterm/index.html b/docs/sp24-midterm/index.html index 8c80ad0..986600c 100644 --- a/docs/sp24-midterm/index.html +++ b/docs/sp24-midterm/index.html @@ -137,6 +137,39 @@

Spring 2024 Midterm Exam

calculators were allowed. Students had 80 minutes to take this exam.


+

The h table records addresses within San Diego. Only 50 +addresses are recorded. The index of the dataframe contains the numbers +1-50 as unique integers.

+ +
+

The o table records information on power outages within +San Diego in April 2024. Only 100 outages are recorded. The index of the +dataframe contains the numbers 1-100 as unique integers.

+ +
+

The j table is a table that links outages to addresses. +Each entry in the j table contains the hid of +the affected address and the oid of the outage. For +example, the first row of the table records that the outage with an +oid of 1 caused the power to go out at addresses with +hid 61 and 88. A single outage can affect multiple +addresses. There are no missing values and no duplicated rows in this +table, and all values are positive integers. This table records all the +addresses affected by all of the outages in 2024 so far.

+ +
+

Problem 1

Fill in Python code below so that the last line of each part evaluates to each desired result using the tables h, @@ -328,41 +361,107 @@

versions of h, j, and o, then perform the join by hand. For example, consider the following example h, j, and o tables:

-
-| **hid** | -|---------| -| 1 | -| 2 | -| 3 | -
-
-| **hid** | **oid** | -|---------|---------| -| 1 | 1 | -| 2 | 1 | -| 2 | 10 | -| 2 | 11 | -| 10 | 3 | -| 11 | 3 | -
-
-| **oid** | -|---------| -| 1 | -| 2 | -| 3 | -
+ + + + + + + + + + + + + + + + + +
hid
1
2
3
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
hidoid
11
21
210
211
103
113
+
+ + + + + + + + + + + + + + + + + +
oid
1
2
3

In this example, whoa would look like the following (omitting other columns besides hid and oid for brevity):

-
-| **hid** | **oid** | -|---------|---------| -| 1 | 1 | -| 2 | 1 | -| NaN | 2 | -| NaN | 3 | -
+ + + + + + + + + + + + + + + + + + + + + + + + + +
hidoid
11
21
NaN2
NaN3

There are 3 cases where rows will be kept for whoa:

  1. When both hid and oid match in the three diff --git a/pages/exams/sp24-midterm.yml b/pages/exams/sp24-midterm.yml index 27dbb80..74be09a 100644 --- a/pages/exams/sp24-midterm.yml +++ b/pages/exams/sp24-midterm.yml @@ -2,6 +2,7 @@ title: 'Spring 2024 Midterm Exam' instructors: Sam Lau context: This exam was administered in-person. The exam was closed-notes, except students were allowed to bring a single two-sided notes sheet. No calculators were allowed. Students had **80 minutes** to take this exam. show_solution: true +data_info: sp24-midterm/sp24-midterm-data-info problems: - sp24-midterm/sp24-mid-q01 - sp24-midterm/sp24-mid-q02 diff --git a/problems/sp24-midterm/sp24-mid-q02.md b/problems/sp24-midterm/sp24-mid-q02.md index be5a825..b026280 100644 --- a/problems/sp24-midterm/sp24-mid-q02.md +++ b/problems/sp24-midterm/sp24-mid-q02.md @@ -40,15 +40,14 @@ Write a **single expression** that evaluates to the number of rows in `whoa`. In We know that `h` has the numbers 1-50 as unique integers in its index, and `o` has the numbers 1-100 as unique integers in its index. However, the `hid` and `oid` columns in `j` have values outside these ranges. To approach this problem, it's easiest to come up with smaller versions of `h`, `j`, and `o`, then perform the join by hand. For example, consider the following example `h`, `j`, and `o` tables: -
    | **hid** | |---------| | 1 | | 2 | | 3 | -
    -
    +--- + | **hid** | **oid** | |---------|---------| | 1 | 1 | @@ -57,26 +56,24 @@ We know that `h` has the numbers 1-50 as unique integers in its index, and `o` h | 2 | 11 | | 10 | 3 | | 11 | 3 | -
    -
    +--- + | **oid** | |---------| | 1 | | 2 | | 3 | -
    + In this example, `whoa` would look like the following (omitting other columns besides `hid` and `oid` for brevity): -
    | **hid** | **oid** | |---------|---------| | 1 | 1 | | 2 | 1 | | NaN | 2 | | NaN | 3 | -
    There are 3 cases where rows will be kept for `whoa`: diff --git a/problems/sp24-midterm/sp24-midterm-data-info.md b/problems/sp24-midterm/sp24-midterm-data-info.md index 2c3a214..ab8e2d6 100644 --- a/problems/sp24-midterm/sp24-midterm-data-info.md +++ b/problems/sp24-midterm/sp24-midterm-data-info.md @@ -3,18 +3,18 @@ The `h` table records addresses within San Diego. Only 50 addresses are recorded - `"number" (int)`: Street address number - `"street" (str)`: Street name -
    +
    The `o` table records information on power outages within San Diego in April 2024. Only 100 outages are recorded. The index of the dataframe contains the numbers 1-100 as unique integers. - `"time" (pd.Timestamp)`: When the outage began - `"duration" (int)`: How long the outage lasted in minutes -
    +
    The `j` table is a table that links outages to addresses. Each entry in the `j` table contains the `hid` of the affected address and the `oid` of the outage. For example, the first row of the table records that the outage with an `oid` of 1 caused the power to go out at addresses with `hid` 61 and 88. A single outage can affect multiple addresses. There are no missing values and no duplicated rows in this table, and all values are positive integers. This table records all the addresses affected by all of the outages in 2024 so far. - `"hid" (int)`: The `hid` of the affected address - `"oid" (int)`: The `oid` of the outage -
    \ No newline at end of file +
    \ No newline at end of file