Skip to content

Commit f5ea0bb

Browse files
assignment 2 python completed
1 parent 4f3dba6 commit f5ea0bb

1 file changed

Lines changed: 119 additions & 29 deletions

File tree

02_activities/assignments/assignment_2.ipynb

Lines changed: 119 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -72,31 +72,100 @@
7272
},
7373
{
7474
"cell_type": "code",
75-
"execution_count": null,
75+
"execution_count": 22,
7676
"metadata": {
7777
"id": "n0m48JsS-nMC"
7878
},
79-
"outputs": [],
79+
"outputs": [
80+
{
81+
"name": "stdout",
82+
"output_type": "stream",
83+
"text": [
84+
"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",
85+
"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",
86+
"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",
87+
"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",
88+
"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",
89+
"0,0,1,2,2,4,2,1,6,4,7,6,6,9,9,15,4,16,18,12,12,5,18,9,5,3,10,3,12,7,8,4,7,3,5,4,4,3,2,1\n",
90+
"0,0,2,2,4,2,2,5,5,8,6,5,11,9,4,13,5,12,10,6,9,17,15,8,9,3,13,7,8,2,8,8,4,2,3,5,4,1,1,1\n",
91+
"0,0,1,2,3,1,2,3,5,3,7,8,8,5,10,9,15,11,18,19,20,8,5,13,15,10,6,10,6,7,4,9,3,5,2,5,3,2,2,1\n",
92+
"0,0,0,3,1,5,6,5,5,8,2,4,11,12,10,11,9,10,17,11,6,16,12,6,8,14,6,13,10,11,4,6,4,7,6,3,2,1,0,0\n",
93+
"0,1,1,2,1,3,5,3,5,8,6,8,12,5,13,6,13,8,16,8,18,15,16,14,12,7,3,8,9,11,2,5,4,5,1,4,1,2,0,0\n",
94+
"0,1,0,0,4,3,3,5,5,4,5,8,7,10,13,3,7,13,15,18,8,15,15,16,11,14,12,4,10,10,4,3,4,5,5,3,3,2,2,1\n",
95+
"0,1,0,0,3,4,2,7,8,5,2,8,11,5,5,8,14,11,6,11,9,16,18,6,12,5,4,3,5,7,8,3,5,4,5,5,4,0,1,1\n",
96+
"0,0,2,1,4,3,6,4,6,7,9,9,3,11,6,12,4,17,13,15,13,12,8,7,4,7,12,9,5,6,5,4,7,3,5,4,2,3,0,1\n",
97+
"0,0,0,0,1,3,1,6,6,5,5,6,3,6,13,3,10,13,9,16,15,9,11,4,6,4,11,11,12,3,5,8,7,4,6,4,1,3,0,0\n",
98+
"0,1,2,1,1,1,4,1,5,2,3,3,10,7,13,5,7,17,6,9,12,13,10,4,12,4,6,7,6,10,8,2,5,1,3,4,2,0,2,0\n",
99+
"0,1,1,0,1,2,4,3,6,4,7,5,5,7,5,10,7,8,18,17,9,8,12,11,11,11,14,6,11,2,10,9,5,6,5,3,4,2,2,0\n",
100+
"0,0,0,0,2,3,6,5,7,4,3,2,10,7,9,11,12,5,12,9,13,19,14,17,5,13,8,11,5,10,9,8,7,5,3,1,4,0,2,1\n",
101+
"0,0,0,1,2,1,4,3,6,7,4,2,12,6,12,4,14,7,8,14,13,19,6,9,12,6,4,13,6,7,2,3,6,5,4,2,3,0,1,0\n",
102+
"0,0,2,1,2,5,4,2,7,8,4,7,11,9,8,11,15,17,11,12,7,12,7,6,7,4,13,5,7,6,6,9,2,1,1,2,2,0,1,0\n",
103+
"0,1,2,0,1,4,3,2,2,7,3,3,12,13,11,13,6,5,9,16,9,19,16,11,8,9,14,12,11,9,6,6,6,1,1,2,4,3,1,1\n",
104+
"0,1,1,3,1,4,4,1,8,2,2,3,12,12,10,15,13,6,5,5,18,19,9,6,11,12,7,6,3,6,3,2,4,3,1,5,4,2,2,0\n",
105+
"0,0,2,3,2,3,2,6,3,8,7,4,6,6,9,5,12,12,8,5,12,10,16,7,14,12,5,4,6,9,8,5,6,6,1,4,3,0,2,0\n",
106+
"0,0,0,3,4,5,1,7,7,8,2,5,12,4,10,14,5,5,17,13,16,15,13,6,12,9,10,3,3,7,4,4,8,2,6,5,1,0,1,0\n",
107+
"0,1,1,1,1,3,3,2,6,3,9,7,8,8,4,13,7,14,11,15,14,13,5,13,7,14,9,10,5,11,5,3,5,1,1,4,4,1,2,0\n",
108+
"0,1,1,1,2,3,5,3,6,3,7,10,3,8,12,4,12,9,15,5,17,16,5,10,10,15,7,5,3,11,5,5,6,1,1,1,1,0,2,1\n",
109+
"0,0,2,1,3,3,2,7,4,4,3,8,12,9,12,9,5,16,8,17,7,11,14,7,13,11,7,12,12,7,8,5,7,2,2,4,1,1,1,0\n",
110+
"0,0,1,2,4,2,2,3,5,7,10,5,5,12,3,13,4,13,7,15,9,12,18,14,16,12,3,11,3,2,7,4,8,2,2,1,3,0,1,1\n",
111+
"0,0,1,1,1,5,1,5,2,2,4,10,4,8,14,6,15,6,12,15,15,13,7,17,4,5,11,4,8,7,9,4,5,3,2,5,4,3,2,1\n",
112+
"0,0,2,2,3,4,6,3,7,6,4,5,8,4,7,7,6,11,12,19,20,18,9,5,4,7,14,8,4,3,7,7,8,3,5,4,1,3,1,0\n",
113+
"0,0,0,1,4,4,6,3,8,6,4,10,12,3,3,6,8,7,17,16,14,15,17,4,14,13,4,4,12,11,6,9,5,5,2,5,2,1,0,1\n",
114+
"0,1,1,0,3,2,4,6,8,6,2,3,11,3,14,14,12,8,8,16,13,7,6,9,15,7,6,4,10,8,10,4,2,6,5,5,2,3,2,1\n",
115+
"0,0,2,3,3,4,5,3,6,7,10,5,10,13,14,3,8,10,9,9,19,15,15,6,8,8,11,5,5,7,3,6,6,4,5,2,2,3,0,0\n",
116+
"0,1,2,2,2,3,6,6,6,7,6,3,11,12,13,15,15,10,14,11,11,8,6,12,10,5,12,7,7,11,5,8,5,2,5,5,2,0,2,1\n",
117+
"0,0,2,1,3,5,6,7,5,8,9,3,12,10,12,4,12,9,13,10,10,6,10,11,4,15,13,7,3,4,2,9,7,2,4,2,1,2,1,1\n",
118+
"0,0,1,2,4,1,5,5,2,3,4,8,8,12,5,15,9,17,7,19,14,18,12,17,14,4,13,13,8,11,5,6,6,2,3,5,2,1,1,1\n",
119+
"0,0,0,3,1,3,6,4,3,4,8,3,4,8,3,11,5,7,10,5,15,9,16,17,16,3,8,9,8,3,3,9,5,1,6,5,4,2,2,0\n",
120+
"0,1,2,2,2,5,5,1,4,6,3,6,5,9,6,7,4,7,16,7,16,13,9,16,12,6,7,9,10,3,6,4,5,4,6,3,4,3,2,1\n",
121+
"0,1,1,2,3,1,5,1,2,2,5,7,6,6,5,10,6,7,17,13,15,16,17,14,4,4,10,10,10,11,9,9,5,4,4,2,1,0,1,0\n",
122+
"0,1,0,3,2,4,1,1,5,9,10,7,12,10,9,15,12,13,13,6,19,9,10,6,13,5,13,6,7,2,5,5,2,1,1,1,1,3,0,1\n",
123+
"0,1,1,3,1,1,5,5,3,7,2,2,3,12,4,6,8,15,16,16,15,4,14,5,13,10,7,10,6,3,2,3,6,3,3,5,4,3,2,1\n",
124+
"0,0,0,2,2,1,3,4,5,5,6,5,5,12,13,5,7,5,11,15,18,7,9,10,14,12,11,9,10,3,2,9,6,2,2,5,3,0,0,1\n",
125+
"0,0,1,3,3,1,2,1,8,9,2,8,10,3,8,6,10,13,11,17,19,6,4,11,6,12,7,5,5,4,4,8,2,6,6,4,2,2,0,0\n",
126+
"0,1,1,3,4,5,2,1,3,7,9,6,10,5,8,15,11,12,15,6,12,16,6,4,14,3,12,9,6,11,5,8,5,5,6,1,2,1,2,0\n",
127+
"0,0,1,3,1,4,3,6,7,8,5,7,11,3,6,11,6,10,6,19,18,14,6,10,7,9,8,5,8,3,10,2,5,1,5,4,2,1,0,1\n",
128+
"0,1,1,3,3,4,4,6,3,4,9,9,7,6,8,15,12,15,6,11,6,18,5,14,15,12,9,8,3,6,10,6,8,7,2,5,4,3,1,1\n",
129+
"0,1,2,2,4,3,1,4,8,9,5,10,10,3,4,6,7,11,16,6,14,9,11,10,10,7,10,8,8,4,5,8,4,4,5,2,4,1,1,0\n",
130+
"0,0,2,3,4,5,4,6,2,9,7,4,9,10,8,11,16,12,15,17,19,10,18,13,15,11,8,4,7,11,6,7,6,5,1,3,1,0,0,0\n",
131+
"0,1,1,3,1,4,6,2,8,2,10,3,11,9,13,15,5,15,6,10,10,5,14,15,12,7,4,5,11,4,6,9,5,6,1,1,2,1,2,1\n",
132+
"0,0,1,3,2,5,1,2,7,6,6,3,12,9,4,14,4,6,12,9,12,7,11,7,16,8,13,6,7,6,10,7,6,3,1,5,4,3,0,0\n",
133+
"0,0,1,2,3,4,5,7,5,4,10,5,12,12,5,4,7,9,18,16,16,10,15,15,10,4,3,7,5,9,4,6,2,4,1,4,2,2,2,1\n",
134+
"0,1,2,1,1,3,5,3,6,3,10,10,11,10,13,10,13,6,6,14,5,4,5,5,9,4,12,7,7,4,7,9,3,3,6,3,4,1,2,0\n",
135+
"0,1,2,2,3,5,2,4,5,6,8,3,5,4,3,15,15,12,16,7,20,15,12,8,9,6,12,5,8,3,8,5,4,1,3,2,1,3,1,0\n",
136+
"0,0,0,2,4,4,5,3,3,3,10,4,4,4,14,11,15,13,10,14,11,17,9,11,11,7,10,12,10,10,10,8,7,5,2,2,4,1,2,1\n",
137+
"0,0,2,1,1,4,4,7,2,9,4,10,12,7,6,6,11,12,9,15,15,6,6,13,5,12,9,6,4,7,7,6,5,4,1,4,2,2,2,1\n",
138+
"0,1,2,1,1,4,5,4,4,5,9,7,10,3,13,13,8,9,17,16,16,15,12,13,5,12,10,9,11,9,4,5,5,2,2,5,1,0,0,1\n",
139+
"0,0,1,3,2,3,6,4,5,7,2,4,11,11,3,8,8,16,5,13,16,5,8,8,6,9,10,10,9,3,3,5,3,5,4,5,3,3,0,1\n",
140+
"0,1,1,2,2,5,1,7,4,2,5,5,4,6,6,4,16,11,14,16,14,14,8,17,4,14,13,7,6,3,7,7,5,6,3,4,2,2,1,1\n",
141+
"0,1,1,1,4,1,6,4,6,3,6,5,6,4,14,13,13,9,12,19,9,10,15,10,9,10,10,7,5,6,8,6,6,4,3,5,2,1,1,1\n",
142+
"0,0,0,1,4,5,6,3,8,7,9,10,8,6,5,12,15,5,10,5,8,13,18,17,14,9,13,4,10,11,10,8,8,6,5,5,2,0,2,0\n",
143+
"0,0,1,0,3,2,5,4,8,2,9,3,3,10,12,9,14,11,13,8,6,18,11,9,13,11,8,5,5,2,8,5,3,5,4,1,3,1,1,0\n"
144+
]
145+
}
146+
],
80147
"source": [
81148
"all_paths = [\n",
82-
" \"python/05_src/data/assignment_2_data/inflammation_01.csv\",\n",
83-
" \"python/05_src/data/assignment_2_data/inflammation_02.csv\",\n",
84-
" \"python/05_src/data/assignment_2_data/inflammation_03.csv\",\n",
85-
" \"python/05_src/data/assignment_2_data/inflammation_04.csv\",\n",
86-
" \"python/05_src/data/assignment_2_data/inflammation_05.csv\",\n",
87-
" \"python/05_src/data/assignment_2_data/inflammation_06.csv\",\n",
88-
" \"python/05_src/data/assignment_2_data/inflammation_07.csv\",\n",
89-
" \"python/05_src/data/assignment_2_data/inflammation_08.csv\",\n",
90-
" \"python/05_src/data/assignment_2_data/inflammation_09.csv\",\n",
91-
" \"python/05_src/data/assignment_2_data/inflammation_10.csv\",\n",
92-
" \"python/05_src/data/assignment_2_data/inflammation_11.csv\",\n",
93-
" \"python/05_src/data/assignment_2_data/inflammation_12.csv\"\n",
149+
" \"C:/users/jsphy/python/05_src/data/assignment_2_data/inflammation_01.csv\",\n",
150+
" \"C:/users/jsphy/python/05_src/data/assignment_2_data/inflammation_02.csv\",\n",
151+
" \"C:/users/jsphy/python/05_src/data/assignment_2_data/inflammation_03.csv\",\n",
152+
" \"C:/users/jsphy/python/05_src/data/assignment_2_data/inflammation_04.csv\",\n",
153+
" \"C:/users/jsphy/python/05_src/data/assignment_2_data/inflammation_05.csv\",\n",
154+
" \"C:/users/jsphy/python/05_src/data/assignment_2_data/inflammation_06.csv\",\n",
155+
" \"C:/users/jsphy/python/05_src/data/assignment_2_data/inflammation_07.csv\",\n",
156+
" \"C:/users/jsphy/python/05_src/data/assignment_2_data/inflammation_08.csv\",\n",
157+
" \"C:/users/jsphy/python/05_src/data/assignment_2_data/inflammation_09.csv\",\n",
158+
" \"C:/users/jsphy/python/05_src/data/assignment_2_data/inflammation_10.csv\",\n",
159+
" \"C:/users/jsphy/python/05_src/data/assignment_2_data/inflammation_11.csv\",\n",
160+
" \"C:/users/jsphy/python/05_src/data/assignment_2_data/inflammation_12.csv\"\n",
94161
"]\n",
95162
"\n",
96163
"with open(all_paths[0], 'r') as f:\n",
97164
" # YOUR CODE HERE: Use the readline() or readlines() method to read the .csv file into a variable\n",
98-
" \n",
99-
" # YOUR CODE HERE: Iterate through the variable using a for loop and print each row for inspection"
165+
" lines = f.readlines()\n",
166+
" # YOUR CODE HERE: Iterate through the variable using a for loop and print each row for inspection\n",
167+
"for line in lines:\n",
168+
" print(line.strip()) \n"
100169
]
101170
},
102171
{
@@ -130,7 +199,7 @@
130199
},
131200
{
132201
"cell_type": "code",
133-
"execution_count": null,
202+
"execution_count": 23,
134203
"metadata": {
135204
"id": "82-bk4CBB1w4"
136205
},
@@ -145,13 +214,13 @@
145214
" # Implement the specific operation based on the 'operation' argument\n",
146215
" if operation == 'mean':\n",
147216
" # YOUR CODE HERE: Calculate the mean (average) number of flare-ups for each patient\n",
148-
"\n",
217+
" summary_values = data.mean(axis=ax) \n",
149218
" elif operation == 'max':\n",
150219
" # YOUR CODE HERE: Calculate the maximum number of flare-ups experienced by each patient\n",
151-
"\n",
220+
" summary_values = data.max(axis=ax) \n",
152221
" elif operation == 'min':\n",
153222
" # YOUR CODE HERE: Calculate the minimum number of flare-ups experienced by each patient\n",
154-
"\n",
223+
" summary_values = data.min(axis=ax)\n",
155224
" else:\n",
156225
" # If the operation is not one of the expected values, raise an error\n",
157226
" raise ValueError(\"Invalid operation. Please choose 'mean', 'max', or 'min'.\")\n",
@@ -161,11 +230,19 @@
161230
},
162231
{
163232
"cell_type": "code",
164-
"execution_count": null,
233+
"execution_count": 24,
165234
"metadata": {
166235
"id": "3TYo0-1SDLrd"
167236
},
168-
"outputs": [],
237+
"outputs": [
238+
{
239+
"name": "stdout",
240+
"output_type": "stream",
241+
"text": [
242+
"60\n"
243+
]
244+
}
245+
],
169246
"source": [
170247
"# Test it out on the data file we read in and make sure the size is what we expect i.e., 60\n",
171248
"# Your output for the first file should be 60\n",
@@ -228,7 +305,7 @@
228305
},
229306
{
230307
"cell_type": "code",
231-
"execution_count": null,
308+
"execution_count": 25,
232309
"metadata": {
233310
"id": "_svDiRkdIwiT"
234311
},
@@ -261,18 +338,30 @@
261338
"\n",
262339
"def detect_problems(file_path):\n",
263340
" #YOUR CODE HERE: Use patient_summary() to get the means and check_zeros() to check for zeros in the means\n",
264-
"\n",
265-
" return"
341+
" # mean inflammation scores for all patients\n",
342+
" mean_inflammations = patient_summary(file_path, 'mean')\n",
343+
" #Check if any mean score is zero\n",
344+
" problem_exists = check_zeros(mean_inflammations)\n",
345+
" return problem_exists"
266346
]
267347
},
268348
{
269349
"cell_type": "code",
270-
"execution_count": null,
350+
"execution_count": 27,
271351
"metadata": {},
272-
"outputs": [],
352+
"outputs": [
353+
{
354+
"name": "stdout",
355+
"output_type": "stream",
356+
"text": [
357+
"False\n"
358+
]
359+
}
360+
],
273361
"source": [
274362
"# Test out your code here\n",
275363
"# Your output for the first file should be False\n",
364+
"\n",
276365
"print(detect_problems(all_paths[0]))"
277366
]
278367
},
@@ -314,7 +403,8 @@
314403
"provenance": []
315404
},
316405
"kernelspec": {
317-
"display_name": "Python 3",
406+
"display_name": "dsi_participant",
407+
"language": "python",
318408
"name": "python3"
319409
},
320410
"language_info": {
@@ -327,7 +417,7 @@
327417
"name": "python",
328418
"nbconvert_exporter": "python",
329419
"pygments_lexer": "ipython3",
330-
"version": "3.11.8"
420+
"version": "3.9.19"
331421
}
332422
},
333423
"nbformat": 4,

0 commit comments

Comments
 (0)