Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
117 changes: 105 additions & 12 deletions 02_activities/assignments/assignment_2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,23 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {
"id": "n0m48JsS-nMC"
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Line 1: 0,0,1,3,1,2,4,7,8,3,3,3,10,5,7,4,7,7,12,18,6,13,11,11,7,7,4,6,8,8,4,4,5,7,3,4,2,3,0,0\n",
"Line 2: 0,1,2,1,2,1,3,2,2,6,10,11,5,9,4,4,7,16,8,6,18,4,12,5,12,7,11,5,11,3,3,5,4,4,5,5,1,1,0,1\n",
"Line 3: 0,1,1,3,3,2,6,2,5,9,5,7,4,5,4,15,5,11,9,10,19,14,12,17,7,12,11,7,4,2,10,5,4,2,2,3,2,2,1,1\n",
"Line 4: 0,0,2,0,4,2,2,1,6,7,10,7,9,13,8,8,15,10,10,7,17,4,4,7,6,15,6,4,9,11,3,5,6,3,3,4,2,3,2,1\n",
"Line 5: 0,1,1,3,3,1,3,5,2,4,4,7,6,5,3,10,8,10,6,17,9,14,9,7,13,9,12,6,7,7,9,6,3,2,2,4,2,0,1,1\n"
]
}
],
"source": [
"all_paths = [\n",
" \"../../05_src/data/assignment_2_data/inflammation_01.csv\",\n",
Expand All @@ -95,10 +107,23 @@
"\n",
"with open(all_paths[0], 'r') as f:\n",
" # YOUR CODE HERE: Use the readline() or readlines() method to read the .csv file into a variable\n",
" \n",
" # YOUR CODE HERE: Iterate through the variable using a for loop and print each row for inspection"
" \n",
" lines = f.readlines()\n",
"\n",
" # YOUR CODE HERE: Iterate through the variable using a for loop and print each row for inspection\n",
"\n",
" for i, line in enumerate(lines[:5], start=1): \n",
" print(f\"Line {i}: {line.strip()}\")\n",
" \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {
Expand Down Expand Up @@ -130,7 +155,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {
"id": "82-bk4CBB1w4"
},
Expand All @@ -145,13 +170,20 @@
" # Implement the specific operation based on the 'operation' argument\n",
" if operation == 'mean':\n",
" # YOUR CODE HERE: Calculate the mean (average) number of flare-ups for each patient\n",
" \n",
" summary_values = np.mean(data, axis=ax)\n",
"\n",
" elif operation == 'max':\n",
" # YOUR CODE HERE: Calculate the maximum number of flare-ups experienced by each patient\n",
"\n",
" summary_values = np.max(data, axis=ax)\n",
"\n",
"\n",
" elif operation == 'min':\n",
" # YOUR CODE HERE: Calculate the minimum number of flare-ups experienced by each patient\n",
"\n",
" summary_values = np.min(data, axis=ax)\n",
"\n",
" else:\n",
" # If the operation is not one of the expected values, raise an error\n",
" raise ValueError(\"Invalid operation. Please choose 'mean', 'max', or 'min'.\")\n",
Expand All @@ -161,11 +193,19 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {
"id": "3TYo0-1SDLrd"
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"60\n"
]
}
],
"source": [
"# Test it out on the data file we read in and make sure the size is what we expect i.e., 60\n",
"# Your output for the first file should be 60\n",
Expand Down Expand Up @@ -251,7 +291,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 14,
"metadata": {
"id": "LEYPM5v4JT0i"
},
Expand All @@ -262,20 +302,72 @@
"def detect_problems(file_path):\n",
" #YOUR CODE HERE: Use patient_summary() to get the means and check_zeros() to check for zeros in the means\n",
"\n",
" return"
" means = patient_summary(file_path, 'mean')\n",
" result = check_zeros(means)\n",
"\n",
" return result"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"def check_zeros(x):\n",
" '''\n",
" Given an array, x, check whether any values in x equal 0.\n",
" Return True if any values found, else returns False.\n",
" '''\n",
" flag = np.where(x == 0)[0]\n",
" return len(flag) > 0\n"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"False\n"
]
}
],
"source": [
"# Test out your code here\n",
"# Your output for the first file should be False\n",
"print(detect_problems(all_paths[0]))"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"False\n",
"False\n"
]
}
],
"source": [
"print(detect_problems(all_paths[0])) # should be False\n",
"print(detect_problems(all_paths[1])) # may be True or False\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {
Expand Down Expand Up @@ -314,7 +406,8 @@
"provenance": []
},
"kernelspec": {
"display_name": "Python 3",
"display_name": "venv",
"language": "python",
"name": "python3"
},
"language_info": {
Expand All @@ -327,7 +420,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down
Loading