Skip to content

Commit

Permalink
Adjust exercises based on feedback pilot (#64)
Browse files Browse the repository at this point in the history
* Adding more explanation to exercises 1 to 3.

* Typos in afternoon exercises 3 to 9.

* Maartens comments on afternoon exercises --> solutions.

* Maarten's comments on afternoon exercises -> exercise notebook.

---------

Co-authored-by: Jelle Treep <[email protected]>
  • Loading branch information
chStaiger and jelletreep authored Jul 17, 2023
1 parent 07c654c commit e518930
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 24 deletions.
28 changes: 21 additions & 7 deletions course_materials/afternoon_exercises.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"metadata": {},
"source": [
"### Exercise 2\n",
"Perform some basic statistics on the weight column. For practical reasons, it can be useful to first create a variable `weight` that contains the just the weight column. It will make the code look a bit cleaner. Can you tell what each method listed below does? Look at our explorative plot, does the statistics make sense?\n",
"Perform some basic statistics on the weight column. For practical reasons, it can be useful to first create a variable `weight` that contains the just the weight column. It will make the code look a bit cleaner. Can you tell what each method listed below does? Look at our explorative plot, do the statistics make sense?\n",
"\n",
"```python\n",
"weight=surveys_df['weight']\n",
Expand Down Expand Up @@ -165,7 +165,7 @@
"### Exercise 3\n",
"- Swap the order of column names in `surveys_df[['plot_id', 'species_id']]`\n",
"- Repeat one of the column names like `surveys_df[['plot_id', 'plot_id', 'species_id']]`\n",
"How does the results look like and why?\n",
"What do the results look like and why?\n",
"- Which error occurrs in `surveys_df['plot_id', 'species_id']` and why?\n",
"- Which error occurrs in `surveys_df['speciess']`?"
]
Expand All @@ -184,7 +184,7 @@
"metadata": {},
"source": [
"### Exercise 4\n",
"What happens when you execute:\n",
"What happens when you call:\n",
"- `surveys_df[0:1]`\n",
"- `surveys_df[:4]`\n",
"- `surveys_df[:-1]`\n",
Expand Down Expand Up @@ -229,7 +229,7 @@
"metadata": {},
"source": [
"### Exercise 6\n",
"- Create a new DataFrame that only contains observations with sex values that are not female or male. Print the number of rows in this new DataFrame. Verify the result by comparing the number of rows in the new DataFrame with the number of rows in the surveys DataFrame where sex is NaN (hint: there is a function isnull).\n",
"- Create a new DataFrame that only contains observations with sex values that are not female or male. Print the number of rows in this new DataFrame. Verify the result by comparing the number of rows in the new DataFrame with the number of rows in the surveys DataFrame where sex is NaN (hint: there is a function `isnull`).\n",
"- Create a new DataFrame that contains only observations that are of sex male or female and where weight values are greater than 0."
]
},
Expand All @@ -247,7 +247,7 @@
"metadata": {},
"source": [
"### Exercise 7: Putting it all together \n",
"1. Clean the column *sex* (leave out samples we do not know whether they are male or female)\n",
"1. Clean the column *sex* (leave out samples of which we do not know whether they are male or female)\n",
"2. Create a new dataframe *clean_df* which only contains rows of which we have a valid value for *sex* and *weight*\n",
"3. Calculate the average weight of that new DataFrame"
]
Expand Down Expand Up @@ -288,7 +288,7 @@
"### Exercise 9\n",
"Investigate the group keys and row indexes for this more complex grouping example. \n",
"Why are there more than 48 groups?\n",
"What happened to the third group and why dos it not turn up in our statistics?"
"What happened to the third group and why does it not turn up in our statistics?"
]
},
{
Expand Down Expand Up @@ -420,8 +420,22 @@
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python"
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.8"
}
},
"nbformat": 4,
Expand Down
36 changes: 25 additions & 11 deletions course_materials/solutions/afternoon_exercises_solutions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@
"metadata": {},
"source": [
"### Exercise 2\n",
"Perform some basic statistics on the weight column. For practical reasons, it can be useful to first create a variable `weight` that contains the just the weight column. It will make the code look a bit cleaner. Can you tell what each method listed below does? Look at our explorative plot, does the statistics make sense?\n",
"Perform some basic statistics on the weight column. For practical reasons, it can be useful to first create a variable `weight` that contains the just the weight column. It will make the code look a bit cleaner. Can you tell what each method listed below does? Look at our explorative plot, do the statistics make sense?\n",
"\n",
"```python\n",
"weight=surveys_df['weight']\n",
"weight.min()\n",
"weight.max()\n",
"weight.mean()\n",
"weight.std()\n",
"weight.counts()\n",
"weight.count()\n",
"```"
]
},
Expand All @@ -69,9 +69,9 @@
"### Exercise 3\n",
"- Swap the order of column names in `surveys_df[['plot_id', 'species_id']]`\n",
"- Repeat one of the column names like `surveys_df[['plot_id', 'plot_id', 'species_id']]`.\n",
"How does the results look like and why?\n",
"- Which error occurrs in `surveys_df['plot_id', 'species_id']` and why?\n",
"- Which error occurrs in `surveys_df['speciess']`?"
"What do the results look like and why?\n",
"- Which error occurs in `surveys_df['plot_id', 'species_id']` and why?\n",
"- Which error occurs in `surveys_df['speciess']`?"
]
},
{
Expand Down Expand Up @@ -123,7 +123,7 @@
"metadata": {},
"source": [
"### Exercise 4\n",
"What happens when you execute:\n",
"What happens when you call:\n",
"- `surveys_df[0:1]`\n",
"- `surveys_df[:4]`\n",
"- `surveys_df[:-1]`"
Expand Down Expand Up @@ -193,7 +193,7 @@
"metadata": {},
"source": [
"### Exercise 7: Putting it all together \n",
"1. Clean the column *sex* (leave out samples we do not know whether they are male or female) and save the result as a new dataframe `clean_df`.\n",
"1. Clean the column *sex* (leave out samples of which we do not know whether they are male or female) and save the result as a new dataframe `clean_df`.\n",
"2. Fill undefined *weight* values with the mean of all valid weights in `surveys_df`.\n",
"3. Calculate the average weight of that new DataFrame `clean_df`"
]
Expand Down Expand Up @@ -247,7 +247,7 @@
"### Exercise 9\n",
"Investigate the group keys and row indexes for this more complex grouping example. \n",
"Why are there more than 48 groups?\n",
"What happened to the third group and why dos it not turn up in our statistics?"
"What happened to the third group and why does it not turn up in our statistics?"
]
},
{
Expand Down Expand Up @@ -354,7 +354,7 @@
"metadata": {},
"outputs": [],
"source": [
"# 3.\n",
"# 3.\n",
"surveys_df_sub_last10 = surveys_df.tail(10)\n",
"surveys_df_sub_last10 = surveys_df_sub_last10.reset_index(drop=True)\n",
"horizontal_stack = pd.concat([surveys_df_sub_first10, surveys_df_sub_last10], axis=1)\n",
Expand All @@ -368,7 +368,7 @@
"metadata": {},
"outputs": [],
"source": [
"# 4.\n",
"# 4.\n",
"horizontal_stack.iloc[:,5]"
]
},
Expand Down Expand Up @@ -402,8 +402,22 @@
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python"
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.8"
}
},
"nbformat": 4,
Expand Down
32 changes: 26 additions & 6 deletions course_materials/solutions/morning_exercises_solutions.ipynb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"cells": [
{
"cell_type": "raw",
"id": "9131db72-c829-4fa8-9782-b276427a6b8e",
"cell_type": "markdown",
"id": "cac5b58d",
"metadata": {},
"source": [
"---\n",
"#### ---\n",
"title: \"Exercises\"\n",
"execute: \n",
" enabled: true\n",
Expand Down Expand Up @@ -68,7 +68,7 @@
"metadata": {},
"source": [
"### Exercise 1\n",
"1. Calculate: One plus five divided by nine amd assign the result of the calculation to a variable.\n",
"1. Calculate: One plus five and divide the sum by nine amd assign the result of the calculation to a variable.\n",
"2. Test if the result is larger than one. (tip: output of the cell should be True or False)\n",
"3. Round off the result to one decimal. Use the function `round`. (tip: use `? round` or you internet search engine for information about how to use the function)"
]
Expand All @@ -90,7 +90,7 @@
"metadata": {},
"outputs": [],
"source": [
"s>1"
"s > 1"
]
},
{
Expand All @@ -100,7 +100,7 @@
"metadata": {},
"outputs": [],
"source": [
"round(s,1)"
"round(s, 1)"
]
},
{
Expand Down Expand Up @@ -174,6 +174,14 @@
"print(1 + \"one\")"
]
},
{
"cell_type": "markdown",
"id": "c04be0a7",
"metadata": {},
"source": [
"**Note**, that the boolean variables `True` and `False` are turned into numbers when used in calculations. `True` becomes `1` and `False` becomes `0`."
]
},
{
"cell_type": "markdown",
"id": "9a563334-42f1-4f7c-b4bc-abe5d2bdb17d",
Expand Down Expand Up @@ -263,6 +271,14 @@
"age[name.index(\"Chloe\")]"
]
},
{
"cell_type": "markdown",
"id": "33ddff9a",
"metadata": {},
"source": [
"**Note**, we can only fetch Claire's age from `age` since the two lists are sorted accordingly. Dictionaries, see next Section, will give us a better way of mapping from one value to another."
]
},
{
"cell_type": "markdown",
"id": "eeb9678b",
Expand Down Expand Up @@ -416,7 +432,11 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
<<<<<<< HEAD
"version": "3.10.8"
=======
"version": "3.10.11"
>>>>>>> main
}
},
"nbformat": 4,
Expand Down

0 comments on commit e518930

Please sign in to comment.