Skip to content

Commit 6a0eb1c

Browse files
committed
edits 2
1 parent d17261f commit 6a0eb1c

File tree

3 files changed

+25
-37
lines changed

3 files changed

+25
-37
lines changed

lessons/1_Functions_and_Conditionals.ipynb

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@
161161
"outputs": [],
162162
"source": [
163163
"# This works\n",
164-
"round(3.000, 2)"
164+
"round(3.0003, 4)"
165165
]
166166
},
167167
{
@@ -283,9 +283,7 @@
283283
"metadata": {},
284284
"outputs": [],
285285
"source": [
286-
"def ...:\n",
287-
" # YOUR CODE HERE\n",
288-
" return ..."
286+
"# YOUR CODE HERE\n"
289287
]
290288
},
291289
{
@@ -336,7 +334,7 @@
336334
"def add_10(x):\n",
337335
" return x + 10\n",
338336
"\n",
339-
"df['pop'].apply(add_10)"
337+
"df['year'].apply(add_10)"
340338
]
341339
},
342340
{
@@ -345,7 +343,7 @@
345343
"source": [
346344
"In the code above, we create a function that adds 10 to whatever is passed into it as an argument.\n",
347345
"\n",
348-
"🔔 <span style=\"color:purple\"> **Question**: What happens when we `apply()` our function to the `pop` column?</span>"
346+
"🔔 <span style=\"color:purple\"> **Question**: What happens when we `apply()` our function to the `year` column?</span>"
349347
]
350348
},
351349
{
@@ -416,7 +414,7 @@
416414
"metadata": {},
417415
"outputs": [],
418416
"source": [
419-
"number = 110\n",
417+
"number = 90\n",
420418
"\n",
421419
"if number > 100:\n",
422420
" print(number, 'is greater than 100.')\n",
@@ -608,7 +606,7 @@
608606
"metadata": {},
609607
"outputs": [],
610608
"source": [
611-
"df['gdpPercap_over_800'] = # Your variable here\n",
609+
"df['gdpPercap_over_800'] = GDP_higher_than_800\n",
612610
"df"
613611
]
614612
},

lessons/2_Iteration_and_Visualization.ipynb

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"### Learning Objectives \n",
1414
" \n",
1515
"* Implement loops to do repeated computations.\n",
16-
"* Understand how to use vectorization in Pandas.\n",
16+
"* Understand how to implement loops in Pandas with a technique called \"vectorization\".\n",
1717
"* Apply several Pandas methods to summarize and manipulate data.\n",
1818
"* Distinguish Pandas methods for `DataFrame` and `Series` objects.\n",
1919
"* Create simple visualizations using Pandas. \n",
@@ -34,17 +34,6 @@
3434
"4. [Methods for `Series` Objects](#series_meth)"
3535
]
3636
},
37-
{
38-
"cell_type": "code",
39-
"execution_count": null,
40-
"metadata": {},
41-
"outputs": [],
42-
"source": [
43-
"import pandas as pd\n",
44-
"import numpy as np\n",
45-
"import matplotlib.pyplot as plt"
46-
]
47-
},
4837
{
4938
"cell_type": "markdown",
5039
"metadata": {},
@@ -55,7 +44,7 @@
5544
"\n",
5645
"The strength of using computers is their speed. We can leverage this through repeated computation, also called iteration. In Python, we can do this using **loops**. \n",
5746
"\n",
58-
"A **[for loop](https://www.w3schools.com/python/python_for_loops.asp)** executes some statements once *for* each value in an interable (like a list or a string). It says: \"*for* each thing in this group, *do* these operations\".\n",
47+
"A **[for loop](https://www.w3schools.com/python/python_for_loops.asp)** executes some statements once *for* each value in an iterable (like a list or a string). It says: \"*for* each thing in this group, *do* these operations\".\n",
5948
"\n",
6049
"Let's take a look at the syntax of a for loop using the above example:"
6150
]
@@ -182,7 +171,7 @@
182171
"In the above example, we are operating on each value in `numbers`. However, instead of simply printing the results, we often will want to save them somehow. We can do this with an **accumulator variable**.\n",
183172
"\n",
184173
"A common strategy in programs is to:\n",
185-
"1. Initialize an *accumulator* variable appropriate to the datatype of the output:\n",
174+
"1. Initialize an accumulator variable appropriate to the datatype of the output:\n",
186175
" * `int` : `0`\n",
187176
" * `str` : `''`\n",
188177
" * `list` : `[]`\n",
@@ -286,6 +275,13 @@
286275
"print(result)"
287276
]
288277
},
278+
{
279+
"cell_type": "markdown",
280+
"metadata": {},
281+
"source": [
282+
"💡 **Tip**: You might also encounter **[while loops](https://www.w3schools.com/python/python_while_loops.asp)**. A while loop says: \"*while* Condition A is true, *do* these operations\". We don't use these loops frequently in this type of programming so we won't cover them here."
283+
]
284+
},
289285
{
290286
"cell_type": "markdown",
291287
"metadata": {},
@@ -397,13 +393,6 @@
397393
"# YOUR CODE HERE\n"
398394
]
399395
},
400-
{
401-
"cell_type": "markdown",
402-
"metadata": {},
403-
"source": [
404-
"💡 **Tip** You might also encounter **[while loops](https://www.w3schools.com/python/python_while_loops.asp)**. A while loop says: \"*while* Condition A is true, *do* these operations\". We don't use these loops frequently in this type of programming so we won't cover them here."
405-
]
406-
},
407396
{
408397
"cell_type": "markdown",
409398
"metadata": {},
@@ -515,7 +504,9 @@
515504
"\n",
516505
"Bar plots show the relationship between a numeric and a categoric variable. Here, we use the `country` (categorical) and `lifeExp` (numeric) columns. Use a bar plot when you want to illustrate differences in frequencies of some category.\n",
517506
"\n",
518-
"In the below cell, we retrieve the 10 data points with the **lowest life expectancy** in our data using the `sort_values()` method, and then plot those data points in a bar plot."
507+
"In the below cell, we retrieve the 10 data points with the **lowest life expectancy** in our data using the `sort_values()` method, and then plot those data points in a bar plot.\n",
508+
"\n",
509+
"💡 **Tip**: Note that `plot.bar()` is a method of its own, and is an alternative to using `plot()` with the `type=bar` argument."
519510
]
520511
},
521512
{
@@ -527,7 +518,7 @@
527518
"# Sort values based on low life expectancy, get top 10\n",
528519
"low_lifeExp = df.sort_values('lifeExp', ascending=True)[:10]\n",
529520
"\n",
530-
"# Visualize with bar plot\n",
521+
"# Visualize with bar plot \n",
531522
"low_lifeExp.plot.bar(x='country', y='lifeExp', figsize=(6,4));"
532523
]
533524
},
@@ -696,12 +687,11 @@
696687
"\n",
697688
"## ❗ Key Points\n",
698689
"\n",
699-
"* A `for` loop executes some statements once for each value in an interable.\n",
700690
"* `for` loops work on lists and other list-like structures, but also on other iterables such as strings.\n",
701-
"* We typically use an aggregator variable to store some information we retrieve using a `for` loop. \n",
702-
"* The `.describe()` method in Pandas summarizes numerical data in a dataset.\n",
703-
"* We typically do not want to use for-loops in Pandas - instead, we use \"vectorized\" operations.\n",
704-
"* The `.plot()` method in Pandas takes a `kind=` argument that determines what kind of plot it is - such as `scatter` or `hist`.\n",
691+
"* We typically use an accumulator variable to store some information we retrieve using a `for` loop. \n",
692+
"* We typically do not use for-loops in Pandas - instead, we use \"vectorized\" operations.\n",
693+
"* Pandas methods work on either `DataFrame` or `Series` objects--make sure you know which!\n",
694+
"* Pandas methods yield as output either `DataFrame` or `Series` objects--make sure you know which!\n",
705695
"\n",
706696
"</div>"
707697
]

solutions/1_Functions_and_Conditionals.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
}
7575
],
7676
"source": [
77-
"number = ...\n",
77+
"number = 80\n",
7878
"\n",
7979
"if number > 100:\n",
8080
" print(number, 'is greater than 100.')\n",

0 commit comments

Comments
 (0)