diff --git a/02_activities/assignments/assignment_2.ipynb b/02_activities/assignments/assignment_2.ipynb index 36a3e2bb7..e81e1a297 100644 --- a/02_activities/assignments/assignment_2.ipynb +++ b/02_activities/assignments/assignment_2.ipynb @@ -79,24 +79,33 @@ "outputs": [], "source": [ "all_paths = [\n", - " \"../../05_src/data/assignment_2_data/inflammation_01.csv\",\n", - " \"../../05_src/data/assignment_2_data/inflammation_02.csv\",\n", - " \"../../05_src/data/assignment_2_data/inflammation_03.csv\",\n", - " \"../../05_src/data/assignment_2_data/inflammation_04.csv\",\n", - " \"../../05_src/data/assignment_2_data/inflammation_05.csv\",\n", - " \"../../05_src/data/assignment_2_data/inflammation_06.csv\",\n", - " \"../../05_src/data/assignment_2_data/inflammation_07.csv\",\n", - " \"../../05_src/data/assignment_2_data/inflammation_08.csv\",\n", - " \"../../05_src/data/assignment_2_data/inflammation_09.csv\",\n", - " \"../../05_src/data/assignment_2_data/inflammation_10.csv\",\n", - " \"../../05_src/data/assignment_2_data/inflammation_11.csv\",\n", - " \"../../05_src/data/assignment_2_data/inflammation_12.csv\"\n", + " \"C:/Users/lungy/Desktop/python/05_src/data/assignment_2_data/inflammation_01.csv\",\n", + " \"C:/Users/lungy/Desktop/python/05_src/data/assignment_2_data/inflammation_02.csv\",\n", + " \"C:/Users/lungy/Desktop/python/05_src/data/assignment_2_data/inflammation_03.csv\",\n", + " \"C:/Users/lungy/Desktop/python/05_src/data/assignment_2_data/inflammation_04.csv\",\n", + " \"C:/Users/lungy/Desktop/python/05_src/data/assignment_2_data/inflammation_05.csv\",\n", + " \"C:/Users/lungy/Desktop/python/05_src/data/assignment_2_data/inflammation_06.csv\",\n", + " \"C:/Users/lungy/Desktop/python/05_src/data/assignment_2_data/inflammation_07.csv\",\n", + " \"C:/Users/lungy/Desktop/python/05_src/data/assignment_2_data/inflammation_08.csv\",\n", + " \"C:/Users/lungy/Desktop/python/05_src/data/assignment_2_data/inflammation_09.csv\",\n", + " \"C:/Users/lungy/Desktop/python/05_src/data/assignment_2_data/inflammation_10.csv\",\n", + " \"C:/Users/lungy/Desktop/python/05_src/data/assignment_2_data/inflammation_11.csv\",\n", + " \"C:/Users/lungy/Desktop/python/05_src/data/assignment_2_data/inflammation_12.csv\"\n", "]\n", "\n", "with open(all_paths[0], 'r') as f:\n", + "\n", " # YOUR CODE HERE: Use the readline() or readlines() method to read the .csv file into a variable\n", + " # READ THE .CSV FILES USING READLINES()\n", + "\n", + " #Read the first data filel and assigne a name called 'patients'\n", + " patients = f.readlines()\n", " \n", - " # YOUR CODE HERE: Iterate through the variable using a for loop and print each row for inspection" + " # YOUR CODE HERE: Iterate through the variable using a for loop and print each row for inspection\n", + "\n", + " # Print out the first data file by rows \n", + "for patient in patients:\n", + " print (patient.strip())\n" ] }, { @@ -142,15 +151,20 @@ " data = np.loadtxt(fname=file_path, delimiter=',') # Load the data from the file\n", " ax = 1 # This specifies that the operation should be done for each row (patient)\n", "\n", + "# Define each operational function: mean, max, min\n", " # 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 =1)\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 =1)\n", + "\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 = 1)\n", "\n", " else:\n", " # If the operation is not one of the expected values, raise an error\n", @@ -161,11 +175,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "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", @@ -228,7 +250,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "metadata": { "id": "_svDiRkdIwiT" }, @@ -261,18 +283,31 @@ "\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", + " \n", + " # Integrate patient_summary function into the check_zeros function\n", + " result=check_zeros(patient_summary(file_path, 'mean'))\n", "\n", - " return" + " return result" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "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", + "\n", + "# Print out the results from the detect_problem\n", "print(detect_problems(all_paths[0]))" ] }, @@ -314,7 +349,8 @@ "provenance": [] }, "kernelspec": { - "display_name": "Python 3", + "display_name": "python-env", + "language": "python", "name": "python3" }, "language_info": { @@ -327,7 +363,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.8" + "version": "3.11.13" } }, "nbformat": 4,