Skip to content

Commit d990da2

Browse files
committed
edits 1
1 parent a4f077b commit d990da2

File tree

3 files changed

+20
-18
lines changed

3 files changed

+20
-18
lines changed
88.8 KB
Binary file not shown.

lessons/1_Functions_and_Conditionals.ipynb

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,34 +49,34 @@
4949
"tags": []
5050
},
5151
"source": [
52-
"<a id='loops'></a>\n",
52+
"## Recap\n",
5353
"\n",
54-
"# Recap\n",
54+
"If the following concepts are unclear to you, we recommend you attend [Python Fundamentals](https://dlab.berkeley.edu/training/upcoming-workshops) first!\n",
5555
"\n",
5656
"**Variables** are names attached to particular values.\n",
5757
"* To create a variable, you assign it a value and then start using it.\n",
5858
"* Assignment is done with a single equals sign `=`.\n",
5959
"* When we write `n = 300`, we are assigning 300 to the variable `n` via the assignment operator `=`.\n",
6060
"\n",
6161
"**Functions** perform actions on \"things\".\n",
62-
"* `print()` `len()`, and `type()`, are some of the most commonly used functions.\n",
63-
"* You can identify a function because of its trailing round parentheses. \n",
62+
"* `print()` `len()`, and `type()` are some of the most commonly used functions.\n",
63+
"* You can identify a function by its trailing round parentheses. \n",
6464
"\n",
6565
"**Arguments** are the \"things\" we perform the action on within a function.\n",
66-
"* They can be variables, datasets, or even other functions!\n",
67-
"* Arguments go inside the trailing parentheses of functions when we call them.\n",
66+
"* Arguments go inside the trailing parentheses of functions when we call them. \n",
67+
"* For instance, in `print('D-Lab')`, the string `D-Lab` is an argument.\n",
6868
"* Arguments are also called inputs or parameters.\n",
6969
"\n",
7070
"**Methods** are type-specific functions.\n",
7171
"* Different data types and structures have functions that only apply to them.\n",
7272
"* For instance, strings have methods that only apply to them (lowercasing, uppercasing, etc.) that won't work with other data types.\n",
73-
"* Methods are accessed using dot notation – e.g. `some_string.lower()`.\n",
73+
"* Methods are accessed using dot notation – for instance, `some_string.lower()` to lowercase a string.\n",
7474
" \n",
7575
"**Pandas** is the most common package used in data analysis, with a focus on data manipulation and processing.\n",
7676
"* Pandas uses the `DataFrame` object to store tabular data.\n",
7777
"* A column in a `DataFrame` is called a `Series`.\n",
7878
"\n",
79-
"Check out our [Python glossary](https://github.com/dlab-berkeley/Python-Fundamentals/blob/main/glossary.md) for definitions to other key vocabulary."
79+
"💡 **Tip**: Check out our [Python glossary](https://github.com/dlab-berkeley/Python-Fundamentals/blob/main/glossary.md) for definitions to other key vocabulary."
8080
]
8181
},
8282
{
@@ -85,7 +85,7 @@
8585
"source": [
8686
"### Our Data\n",
8787
"\n",
88-
"The data we will be using in this workshop comes from [Gapminder](https://www.gapminder.org/data/), an independent educational non-profit fighting global misconceptions. The dataset contains data for 142 countries, with values for life expectancy, GDP per capita, and population, every five years, from 1952 to 2007."
88+
"The data we will be using in this workshop comes from [Gapminder](https://www.gapminder.org/data/), an independent educational non-profit fighting global misconceptions. The dataset contains data for 142 countries, with values for life expectancy, GDP per capita, GNI per capita, and population, every five years, from 1952 to 2007."
8989
]
9090
},
9191
{
@@ -124,6 +124,8 @@
124124
"\n",
125125
"# Functions and Arguments\n",
126126
"\n",
127+
"In today's workshop, we will be **applying a function to a DataFrame**. This will give us the opportunity to learn more about functions--including how to write one!\n",
128+
"\n",
127129
"Recall that arguments are information that goes into a function. The order of arguments matters if we do not specify the so-called **keywords**. For instance, let's see the documentation of the `round()` function:"
128130
]
129131
},
@@ -353,10 +355,10 @@
353355
"\n",
354356
"The most widely used conditional is the **if-statement**. An if-statement controls whether some block of code is executed or not.\n",
355357
"\n",
356-
"* The first line opens with the `if` keyword and contains a Boolean variable or expression. It ends with a colon. If the expression evaluates to `True`, the block of code will run.\n",
357-
"* The body, containing whatever code to execute if the condition is met, is indented.\n",
358+
"* The first line opens with the `if` keyword and contains an expression to be evaluated. It ends with a colon. \n",
359+
"* The body of the if-statement is indented. It contains the code to execute **if the condition is met**. If it is not met, it will be skipped.\n",
358360
"\n",
359-
"So, if the Boolean expression is `True`, the body of an if-statement is run. If not, it's skipped. Let's look at an example:"
361+
"Let's look at an example:"
360362
]
361363
},
362364
{
@@ -572,7 +574,7 @@
572574
"source": [
573575
"## 🥊 Challenge 3: Working With Comparison Operators\n",
574576
"\n",
575-
"Select the `gdpPercap` column and apply a boolean mask to select all values higher than 800. Assign it to a variable with a name of your choosing."
577+
"Select the `gdpPercap` column and apply a boolean mask to select **all values higher than 800**. Assign it to a variable with a name of your choosing."
576578
]
577579
},
578580
{
@@ -590,7 +592,7 @@
590592
"cell_type": "markdown",
591593
"metadata": {},
592594
"source": [
593-
"Let's add this last `Series` as a column to our data frame. We can add a column by assigning a series to a new column name in bracket notation. "
595+
"Let's add this last `Series` as a column to our DataFrame. We can add a column by assigning a series to a new column name in bracket notation. "
594596
]
595597
},
596598
{
@@ -627,7 +629,7 @@
627629
"\n",
628630
"Let's put everything we've learned together.\n",
629631
"\n",
630-
"Say that we want to create a new column in our dataset that classifies our datapoints in terms of the level of development, as measured by per capita gross national income (GNI). [This UN document](https://www.un.org/en/development/desa/policy/wesp/wesp_current/2014wesp_country_classification.pdf) outlines some rules for this.\n",
632+
"Say that we want to create a new column in our dataset that classifies our datapoints in terms of the level of development, as measured by per capita gross national income (GNI). [This UN document](https://www.un.org/en/development/desa/policy/wesp/wesp_current/2014wesp_country_classification.pdf) outlines some rules for this (see page 144).\n",
631633
"\n",
632634
"A good way to approach these kinds of problems is to write down all the steps you need to take. Then, you write your code by following the steps. In this case, we need to do the following:\n",
633635
"\n",

solutions/1_Functions_and_Conditionals.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
},
2626
{
2727
"cell_type": "code",
28-
"execution_count": 16,
28+
"execution_count": 4,
2929
"metadata": {},
3030
"outputs": [
3131
{
@@ -34,15 +34,15 @@
3434
"89.6"
3535
]
3636
},
37-
"execution_count": 16,
37+
"execution_count": 4,
3838
"metadata": {},
3939
"output_type": "execute_result"
4040
}
4141
],
4242
"source": [
4343
"def convert_temp(celcius):\n",
4444
" # write your code here\n",
45-
" return(celcius * 1.8 + 32)\n",
45+
" return celcius * 1.8 + 32\n",
4646
"\n",
4747
"convert_temp(32)"
4848
]

0 commit comments

Comments
 (0)