Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 53 additions & 14 deletions 02_activities/assignments/assignment_2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,20 @@
"metadata": {
"id": "n0m48JsS-nMC"
},
"outputs": [],
"outputs": [
{
"ename": "FileNotFoundError",
"evalue": "[Errno 2] No such file or directory: 'python/05_src/data/assignment_2_data/inflammation_01.csv'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mFileNotFoundError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[21], line 16\u001b[0m\n\u001b[1;32m 1\u001b[0m all_paths \u001b[38;5;241m=\u001b[39m [\n\u001b[1;32m 2\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mpython/05_src/data/assignment_2_data/inflammation_01.csv\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[1;32m 3\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mpython/05_src/data/assignment_2_data/inflammation_02.csv\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 13\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mpython/05_src/data/assignment_2_data/inflammation_12.csv\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 14\u001b[0m ]\n\u001b[0;32m---> 16\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m \u001b[38;5;28;43mopen\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mall_paths\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mr\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m \u001b[38;5;28;01mas\u001b[39;00m f:\n\u001b[1;32m 17\u001b[0m lines \u001b[38;5;241m=\u001b[39m f\u001b[38;5;241m.\u001b[39mreadlines()\n\u001b[1;32m 18\u001b[0m \u001b[38;5;66;03m# YOUR CODE HERE: Use the readline() or readlines() method to read the .csv file into a variable\u001b[39;00m\n\u001b[1;32m 19\u001b[0m \n\u001b[1;32m 20\u001b[0m \u001b[38;5;66;03m# YOUR CODE HERE: Iterate through the variable using a for loop and print each row for inspection\u001b[39;00m\n",
"File \u001b[0;32m/opt/miniconda3/envs/dsi_participant/lib/python3.9/site-packages/IPython/core/interactiveshell.py:310\u001b[0m, in \u001b[0;36m_modified_open\u001b[0;34m(file, *args, **kwargs)\u001b[0m\n\u001b[1;32m 303\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m file \u001b[38;5;129;01min\u001b[39;00m {\u001b[38;5;241m0\u001b[39m, \u001b[38;5;241m1\u001b[39m, \u001b[38;5;241m2\u001b[39m}:\n\u001b[1;32m 304\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\n\u001b[1;32m 305\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mIPython won\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mt let you open fd=\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mfile\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m by default \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 306\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mas it is likely to crash IPython. If you know what you are doing, \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 307\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124myou can use builtins\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m open.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 308\u001b[0m )\n\u001b[0;32m--> 310\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mio_open\u001b[49m\u001b[43m(\u001b[49m\u001b[43mfile\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n",
"\u001b[0;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: 'python/05_src/data/assignment_2_data/inflammation_01.csv'"
]
}
],
"source": [
"all_paths = [\n",
" \"python/05_src/data/assignment_2_data/inflammation_01.csv\",\n",
Expand All @@ -94,9 +107,12 @@
"]\n",
"\n",
"with open(all_paths[0], 'r') as f:\n",
" lines = f.readlines()\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"
" # YOUR CODE HERE: Iterate through the variable using a for loop and print each row for inspection\n",
"for line in lines:\n",
" print(line.strip())"
]
},
{
Expand Down Expand Up @@ -130,7 +146,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 15,
"metadata": {
"id": "82-bk4CBB1w4"
},
Expand All @@ -144,12 +160,15 @@
"\n",
" # Implement the specific operation based on the 'operation' argument\n",
" if operation == 'mean':\n",
" summary_values = np.mean(data, axis=ax)\n",
" # YOUR CODE HERE: Calculate the mean (average) number of flare-ups for each patient\n",
"\n",
" elif operation == 'max':\n",
" summary_values = np.max(data, axis=ax) \n",
" # YOUR CODE HERE: Calculate the maximum number of flare-ups experienced by each patient\n",
"\n",
" elif operation == 'min':\n",
" summary_values = np.min(data, axis=ax)\n",
" # YOUR CODE HERE: Calculate the minimum number of flare-ups experienced by each patient\n",
"\n",
" else:\n",
Expand All @@ -161,11 +180,19 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 16,
"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 @@ -228,7 +255,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 17,
"metadata": {
"id": "_svDiRkdIwiT"
},
Expand All @@ -251,7 +278,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 19,
"metadata": {
"id": "LEYPM5v4JT0i"
},
Expand All @@ -260,16 +287,27 @@
"# Define your function `detect_problems` here\n",
"\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",
" return"
" mean_inflammation = patient_summary(file_path, 'mean')\n",
" if check_zeros(mean_inflammation):\n",
" return True\n",
" else:\n",
" return False\n",
" #YOUR CODE HERE: Use patient_summary() to get the means and check_zeros() to check for zeros in the means\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 20,
"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",
Expand Down Expand Up @@ -314,7 +352,8 @@
"provenance": []
},
"kernelspec": {
"display_name": "Python 3",
"display_name": "dsi_participant",
"language": "python",
"name": "python3"
},
"language_info": {
Expand All @@ -327,7 +366,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
"version": "3.9.21"
}
},
"nbformat": 4,
Expand Down