From 5e5742abc64ff13fe846b72026f9a46a335a5197 Mon Sep 17 00:00:00 2001 From: ottp613 Date: Thu, 11 Dec 2025 12:54:23 -0500 Subject: [PATCH 1/4] Enhance data processing and problem detection Updated the code to read a CSV file and added logic to calculate mean, max, and min flare-ups. Implemented a function to detect problems in the data. --- 02_activities/assignments/assignment_2.ipynb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/02_activities/assignments/assignment_2.ipynb b/02_activities/assignments/assignment_2.ipynb index fdaead28..5ed93f69 100644 --- a/02_activities/assignments/assignment_2.ipynb +++ b/02_activities/assignments/assignment_2.ipynb @@ -95,8 +95,10 @@ "\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", + " dataset = f.readlines()\n", # reads only first item inflammation_01.csv " # YOUR CODE HERE: Iterate through the variable using a for loop and print each row for inspection" + " for x in dataset:\n", + " print(x)" ] }, { @@ -145,12 +147,15 @@ " # 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", + " 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", + " summary_values = np.max(data, axis=ax)\n", "\n", " elif operation == 'min':\n", " # YOUR CODE HERE: Calculate the minimum number of flare-ups experienced by each patient\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", @@ -261,6 +266,11 @@ "\n", "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", + " mean_data = patient_summary(file_path, 'mean')\n", + " result = check_zeros(mean_data)\n", + " if result:\n", + " print(f\"check zero returned {result}, i.e average (mean) inflammation score of 0")\n", + " return result" "\n", " return" ] From be364459822e46235abc13a8e6e392e495d5e2aa Mon Sep 17 00:00:00 2001 From: ottp613 Date: Thu, 11 Dec 2025 12:56:36 -0500 Subject: [PATCH 2/4] Fix print statement formatting in assignment_2.ipynb --- 02_activities/assignments/assignment_2.ipynb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/02_activities/assignments/assignment_2.ipynb b/02_activities/assignments/assignment_2.ipynb index 5ed93f69..43f4b396 100644 --- a/02_activities/assignments/assignment_2.ipynb +++ b/02_activities/assignments/assignment_2.ipynb @@ -95,6 +95,7 @@ "\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", " dataset = f.readlines()\n", # reads only first item inflammation_01.csv " # YOUR CODE HERE: Iterate through the variable using a for loop and print each row for inspection" " for x in dataset:\n", @@ -269,7 +270,7 @@ " mean_data = patient_summary(file_path, 'mean')\n", " result = check_zeros(mean_data)\n", " if result:\n", - " print(f\"check zero returned {result}, i.e average (mean) inflammation score of 0")\n", + " print(f\"check zero returned {result}, i.e average (mean) inflammation score of 0"), " return result" "\n", " return" From 39a381dffbd246b9091de9403283b88d9f63f796 Mon Sep 17 00:00:00 2001 From: ottp613 Date: Thu, 11 Dec 2025 12:58:49 -0500 Subject: [PATCH 3/4] Fix CSV reading and problem detection logic Updated the code to read the entire CSV file into a variable and improved the function for detecting problems. --- 02_activities/assignments/assignment_2.ipynb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/02_activities/assignments/assignment_2.ipynb b/02_activities/assignments/assignment_2.ipynb index 43f4b396..8598526f 100644 --- a/02_activities/assignments/assignment_2.ipynb +++ b/02_activities/assignments/assignment_2.ipynb @@ -96,7 +96,8 @@ "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", - " dataset = f.readlines()\n", # reads only first item inflammation_01.csv + " dataset = f.readlines(), + " # reads only first item inflammation_01.csv " # YOUR CODE HERE: Iterate through the variable using a for loop and print each row for inspection" " for x in dataset:\n", " print(x)" @@ -269,8 +270,6 @@ " #YOUR CODE HERE: Use patient_summary() to get the means and check_zeros() to check for zeros in the means\n", " mean_data = patient_summary(file_path, 'mean')\n", " result = check_zeros(mean_data)\n", - " if result:\n", - " print(f\"check zero returned {result}, i.e average (mean) inflammation score of 0"), " return result" "\n", " return" From b650ce191bae99f2d65e48c34d98ae8eb7a8ba62 Mon Sep 17 00:00:00 2001 From: ottp613 Date: Thu, 11 Dec 2025 13:02:39 -0500 Subject: [PATCH 4/4] Refactor dataset reading and loop for clarity --- 02_activities/assignments/assignment_2.ipynb | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/02_activities/assignments/assignment_2.ipynb b/02_activities/assignments/assignment_2.ipynb index 8598526f..beea739b 100644 --- a/02_activities/assignments/assignment_2.ipynb +++ b/02_activities/assignments/assignment_2.ipynb @@ -95,11 +95,10 @@ "\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", - " dataset = f.readlines(), + " dataset = f.readlines()\n" " # reads only first item inflammation_01.csv " # YOUR CODE HERE: Iterate through the variable using a for loop and print each row for inspection" - " for x in dataset:\n", + " for row in dataset:\n", " print(x)" ] }, @@ -150,15 +149,12 @@ " if operation == 'mean':\n", " # YOUR CODE HERE: Calculate the mean (average) number of flare-ups for each patient\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", " summary_values = np.max(data, axis=ax)\n", - "\n", " elif operation == 'min':\n", " # YOUR CODE HERE: Calculate the minimum number of flare-ups experienced by each patient\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", @@ -271,8 +267,6 @@ " mean_data = patient_summary(file_path, 'mean')\n", " result = check_zeros(mean_data)\n", " return result" - "\n", - " return" ] }, {