Skip to content

Commit e21bad4

Browse files
committed
minor edits
1 parent e1de796 commit e21bad4

File tree

4 files changed

+13
-16
lines changed

4 files changed

+13
-16
lines changed

images/for.png

-288 Bytes
Loading

images/functions.png

40 KB
Loading

lessons/1_Functions_and_Conditionals.ipynb

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -207,18 +207,11 @@
207207
"source": [
208208
"## Basic Function Syntax\n",
209209
"\n",
210-
"Writing a function in Python is pretty easy! You need to know a few things:\n",
210+
"Writing a function in Python is pretty easy! Let's take a look at a simple function that converts feet into meters:\n",
211211
"\n",
212-
"* Functions begin with the keyword `def`.\n",
213-
"* This keyword is followed by the function *name*.\n",
214-
" * The name must obey the same rules as variable names.\n",
215-
"* The **arguments** or **parameters** are defined in parentheses as variable names.\n",
216-
" * Use empty parentheses if the function doesn't take any inputs.\n",
217-
"* A colon indicates the end of the function *signature* (the first line).\n",
218-
"* An indented block of code denotes the start of the *body*.\n",
219-
"* The final line should be a `return` statement with the value(s) to be returned from the function.\n",
212+
"<img src=\"../images/functions.png\" alt=\"Aspects of a Python Function\" width=\"700\"/>\n",
220213
"\n",
221-
"Let's take a look at a simple function that converts feet into meters:"
214+
"Here's the same function written out:"
222215
]
223216
},
224217
{
@@ -313,7 +306,7 @@
313306
"metadata": {},
314307
"source": [
315308
"Here's what's happening to our DataFrame when we perform that operation:\n",
316-
"<img src=\"../images/vectorized.png\" alt=\"Vectorization in Pandas with scalar\" width=\"500\"/>"
309+
"<img src=\"../images/vectorized.png\" alt=\"Vectorization in Pandas with scalar\" width=\"600\"/>"
317310
]
318311
},
319312
{
@@ -322,7 +315,7 @@
322315
"source": [
323316
"## How to `apply()` a Function\n",
324317
"\n",
325-
"Similarly, the Pandas `.apply()` method allows you to apply a function over an entire column of a dataframe. Here's an example: "
318+
"We can also use a more general technique: `apply()`. `apply()` takes any function and **applies** it over every entry of the column. Let's see how we can do the same operation as above using `apply()`."
326319
]
327320
},
328321
{
@@ -341,7 +334,7 @@
341334
"cell_type": "markdown",
342335
"metadata": {},
343336
"source": [
344-
"In the code above, we create a function that adds 10 to whatever comes into it.\n",
337+
"In the code above, we create a function that adds 10 to whatever is passed into it as an argument.\n",
345338
"\n",
346339
"🔔 <span style=\"color:purple\"> **Question**: What happens when we `apply()` our function to the `pop` column?</span>"
347340
]

lessons/2_Iteration_and_Visualization.ipynb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"\n",
5454
"# Iteration: Loops\n",
5555
"\n",
56-
"The strength of using computers is their speed. We can leverage this through iteration using **loops**. \n",
56+
"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",
5757
"\n",
5858
"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",
5959
"\n",
@@ -155,7 +155,7 @@
155155
"source": [
156156
"## Conditionals and Loops\n",
157157
"\n",
158-
"Recall that we can use `if`-statements to check if a condition is `True` or `False`. Also recall that `True` and `False` are called **Booleans values**.\n",
158+
"Recall that we can use `if`-statements to check if a condition is `True` or `False`. Also recall that `True` and `False` are called **Boolean values**.\n",
159159
"\n",
160160
"Conditionals are particularly useful when we're iterating through a list, and want to perform some operation only on specific components of that list that satisfy a certain condition."
161161
]
@@ -179,6 +179,8 @@
179179
"source": [
180180
"## Aggregating Values With Loops\n",
181181
"\n",
182+
"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",
183+
"\n",
182184
"A common strategy in programs is to:\n",
183185
"1. Initialize an *accumulator* variable appropriate to the datatype of the output:\n",
184186
" * `int` : `0`\n",
@@ -358,7 +360,7 @@
358360
"source": [
359361
"Here's what's happening to our DataFrame when we perform that operation:\n",
360362
"\n",
361-
"<img src=\"../images/vectorized2.png\" alt=\"Vectorizing in Pandas – multiplying columns\" width=\"500\"/>"
363+
"<img src=\"../images/vectorized2.png\" alt=\"Vectorizing in Pandas – multiplying columns\" width=\"600\"/>"
362364
]
363365
},
364366
{
@@ -482,6 +484,8 @@
482484
"source": [
483485
"## Sorting Values\n",
484486
"\n",
487+
"Let's say we want to find the countries with the highest `gdpPercap`.\n",
488+
"\n",
485489
"If we want to sort the values in a DataFrame we can use the [`sort_values()`](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.sort_values.html) method on a DataFrame. It takes as an argument the column we want to sort the DataFrame on. \n",
486490
"\n",
487491
"⚠️ **Warning:** By default, `sort_values()` sorts in **ascending order**."

0 commit comments

Comments
 (0)