From 553054a3d3969637b2f2e6960bfd7a533169786d Mon Sep 17 00:00:00 2001 From: Emily Grabowski Date: Thu, 29 Sep 2022 14:45:40 -0700 Subject: [PATCH 1/3] Resolve issues from last iteration + Reorder Custom Functions Moved custom functions notebook to Day 1 and shortened notebooks 5 and 6 to accommodate. Addressed typos and clarifications in Days 1-4 --- ...hop_setup.ipynb => 00_workshop_setup.ipynb | 0 lessons/Part1/01_introduction.ipynb | 2 +- lessons/Part1/02_jupyter_notebooks.ipynb | 56 +- lessons/Part1/03_variables.ipynb | 49 +- lessons/Part1/04_data_types.ipynb | 264 ++---- lessons/Part1/05_functions.ipynb | 328 +------ .../06_custom_functions.ipynb} | 378 +++----- .../07_dictionaries_and_dataframes.ipynb | 473 ---------- .../Part2/{06_lists.ipynb => 07_lists.ipynb} | 0 .../08_dictionaries_and_dataframes.ipynb | 298 ++++++ .../Part2/{08_loops.ipynb => 09_loops.ipynb} | 10 +- ...nditionals.ipynb => 10_conditionals.ipynb} | 24 - lessons/Part3/11_libraries.ipynb | 2 +- lessons/Part3/12_file_io.ipynb | 16 +- lessons/Part3/13_pandas.ipynb | 6 +- lessons/Part3/14_statsmodels.ipynb | 2 +- lessons/Part4/15_errors.ipynb | 147 +-- lessons/Part4/16_style.ipynb | 27 +- lessons/Part4/17_project.ipynb | 22 +- solutions/03_variables_solutions.ipynb | 133 +-- solutions/04_data_types_solutions.ipynb | 186 +--- solutions/05_functions_solutions.ipynb | 107 +-- ...ctions.ipynb => 06_custom_functions.ipynb} | 108 ++- solutions/{06_lists.ipynb => 07_lists.ipynb} | 0 ...b => 08_dictionaries_and_dataframes.ipynb} | 2 +- solutions/{08_loops.ipynb => 09_loops.ipynb} | 0 ...nditionals.ipynb => 10_conditionals.ipynb} | 0 solutions/11_libraries.ipynb | 2 +- solutions/13_pandas.ipynb | 870 +----------------- 29 files changed, 763 insertions(+), 2749 deletions(-) rename lessons/Part1/00_workshop_setup.ipynb => 00_workshop_setup.ipynb (100%) rename lessons/{Part2/10_custom_functions.ipynb => Part1/06_custom_functions.ipynb} (61%) delete mode 100644 lessons/Part2/07_dictionaries_and_dataframes.ipynb rename lessons/Part2/{06_lists.ipynb => 07_lists.ipynb} (100%) create mode 100644 lessons/Part2/08_dictionaries_and_dataframes.ipynb rename lessons/Part2/{08_loops.ipynb => 09_loops.ipynb} (98%) rename lessons/Part2/{09_conditionals.ipynb => 10_conditionals.ipynb} (97%) rename solutions/{10_custom_functions.ipynb => 06_custom_functions.ipynb} (67%) rename solutions/{06_lists.ipynb => 07_lists.ipynb} (100%) rename solutions/{07_dictionaries_and_dataframes.ipynb => 08_dictionaries_and_dataframes.ipynb} (95%) rename solutions/{08_loops.ipynb => 09_loops.ipynb} (100%) rename solutions/{09_conditionals.ipynb => 10_conditionals.ipynb} (100%) diff --git a/lessons/Part1/00_workshop_setup.ipynb b/00_workshop_setup.ipynb similarity index 100% rename from lessons/Part1/00_workshop_setup.ipynb rename to 00_workshop_setup.ipynb diff --git a/lessons/Part1/01_introduction.ipynb b/lessons/Part1/01_introduction.ipynb index 6a5df28..6a4b19b 100644 --- a/lessons/Part1/01_introduction.ipynb +++ b/lessons/Part1/01_introduction.ipynb @@ -29,7 +29,7 @@ "\n", "\n", "\n", - "When you're programming, 80% or more of your time will be spent debugging, looking stuff up (like program-specific syntax, [documentation](https://github.com/dlab-berkeley/python-intensive/blob/master/Glossary.md#documentation) for packages, useful functions, etc.), or testing. Relatively little time is actually spent typing out the code - most of it goes into the thinking, planning, and testing to ensure well-designed code!\n", + "When you're programming, 80% or more of your time will be spent debugging, looking stuff up (like program-specific syntax, [documentation](https://github.com/dlab-berkeley/python-intensive/blob/master/glossary.md#documentation) for packages, useful functions, etc.), or testing. Relatively little time is actually spent typing out the code - most of it goes into the thinking, planning, and testing to ensure well-designed code!\n", "\n", "## Coding Strategies\n", "\n", diff --git a/lessons/Part1/02_jupyter_notebooks.ipynb b/lessons/Part1/02_jupyter_notebooks.ipynb index f8f0e89..5ab979d 100644 --- a/lessons/Part1/02_jupyter_notebooks.ipynb +++ b/lessons/Part1/02_jupyter_notebooks.ipynb @@ -29,17 +29,9 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Hello World!\n" - ] - } - ], + "outputs": [], "source": [ "print(\"Hello World!\")" ] @@ -48,7 +40,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "If you hit `Enter` only, Jupyter Notebook gives you another line in the current cell.\n", + "**Note:** If you hit `Enter` only, Jupyter Notebook gives you another line in the current cell.\n", "\n", "This allows you to compose multi-line commands and submit them to Python all at once.\n", "\n", @@ -57,17 +49,9 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "3\n" - ] - } - ], + "outputs": [], "source": [ "a = 1 + 2\n", "print(a)" @@ -132,17 +116,9 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "And three shall be the count.\n" - ] - } - ], + "outputs": [], "source": [ "mystring = \"And three shall be the count.\" \n", "\n", @@ -158,17 +134,9 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "And three shall be the count.\n" - ] - } - ], + "outputs": [], "source": [ "print(mystring)" ] @@ -225,7 +193,7 @@ "\n", "Simply place a pound sign `#` at the beginning of the line, and that line won't run. Any uncommented lines will be treated as code.\n", "\n", - "Try running the cell below, then comment out `bad_thing`, and run it again. What changes?\n" + "Try running the cell below, then comment out the last two lines and run it again. What changes?\n" ] }, { @@ -246,11 +214,11 @@ "source": [ "### Indenting\n", "\n", - "Consistent indentation is essential in Python. Python pays close attention to blankspaces, and uses this to understand how you're structuring code. So, you're only supposed to add spaces or indents in places where Python expects you to - otherwise, you'll run into an error.\n", + "Consistent indentation is essential in Python. Python pays close attention to blank spaces, and uses this to understand how you're structuring code. So, you're only supposed to add spaces or indents in places where Python expects you to - otherwise, you'll run into an error.\n", "\n", "To move multiple lines of code at once, you can select them and then hit `Control + ]` to indent them (move to the right), or `Control + [` to dedent them to the left.\n", "\n", - "For Macs, use `Command` in place of `Control`.\n", + "**Note:** For Macs, use `Command` in place of `Control`.\n", "\n", "Read the error message down below. What is the error type? How can we fix it?" ] diff --git a/lessons/Part1/03_variables.ipynb b/lessons/Part1/03_variables.ipynb index 1992df5..f0ebe0b 100644 --- a/lessons/Part1/03_variables.ipynb +++ b/lessons/Part1/03_variables.ipynb @@ -45,7 +45,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "To print multiple values, separate each item to print with a space." + "Print statements are super useful pieces of code to get a window into what values a variable has. To print multiple values, separate each item to print with a space." ] }, { @@ -61,7 +61,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "In addition, the argument `sep` (short for separator) can be used to control what goes in between each item." + "In addition, the argument `sep` (short for separator) can be used to control what goes in between each item. What will the following line of code return?" ] }, { @@ -142,7 +142,7 @@ "* **Operators** (special symbols that perform calculations) are shown in purple in a Jupyter Notebook. These are special symbols that tell Python to perform certain operations.\n", "* **Functions** are processes that perform multiple operations on variables. We will cover these in a later notebook. \n", "\n", - "Let's check out some common operations below. Note what values get substituted in for the variables in each operation. " + "Let's check out some common operations below. Predict the outputs of each of the lines of code below. Note what values get substituted in for the variables in each operation. " ] }, { @@ -176,41 +176,11 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Challenge 2: Words to Code\n", - "\n", - "Translate the following line into code and save the result to a variable. \n", - "\n", - "Divide 15 by the sum of a and three times b. Multiply the result by 2 and raise it to the 3rd power. What is the result?\n", - "\n", - "**Hint**: Order of operations applies in Python (i.e., PEMDAS)." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "a = 2\n", - "b = 3" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "How many lines of code did you do the challenge in? Can you do it in a single line? What did you name your variable?" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Challenge 3: Swapping Values\n", + "## Challenge 2: Swapping Values\n", "\n", "Let's say we have two variables and we want to swap the values for each of them. \n", "\n", - "Does the following method accomplish the goal? What is the value of first and last at the end of the cell? `" + "Does the following method accomplish the goal? (**Hint**: What is the value of first and last at the end of the cell?) `" ] }, { @@ -249,15 +219,8 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "This is a common technique that is used for swapping variables around. However, often we might choose to just use new variables, rather than overwrite the ones here. Can you think of a reason why we might avoid overwriting a variable?" + "This is a common technique that is used for swapping variables around. However, often we might choose to just use new variables, rather than overwrite the ones here. Can you think of a reason why we might avoid overwriting a variable? How about a reason why we *would* overwrite a variable?" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { diff --git a/lessons/Part1/04_data_types.ipynb b/lessons/Part1/04_data_types.ipynb index 42a0368..fc26107 100644 --- a/lessons/Part1/04_data_types.ipynb +++ b/lessons/Part1/04_data_types.ipynb @@ -24,41 +24,27 @@ "* We use the `type()` **function** to identify what the type is of a current variable. Functions are signified by parentheses following them, which contain any inputs to the function.\n", "\n", "\n", - "Let's check the types of some variables below. Predict the type for each variable. Were you surprised by any of the answers?" + "Let's check the types of some variables below. Predict the type for each variable. What clues in the variable assignment line helped indicate type?" ] }, { "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "\n", - "\n" - ] - } - ], + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "pi = 3.14159\n", "print(type(pi))\n", "\n", - "fitness = 'average'\n", - "print(type(fitness))\n", - "\n", - "\n", - "pi2 = '3.14159'\n", - "print(type(pi2))" + "shape = 'diamond'\n", + "print(type(shape))\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Remember that when a variable is called, it takes the most recent value assigned to it, so calling `type(pi)` would be the same as `type(3.14159)`." + "Remember that when a variable is called, it takes the most recent value assigned to it, so calling `type(pi)` would be the same as `type(3.14159)`. This makes `type()` useful for debugging code by tracking how the variables change throughout the code.\n" ] }, { @@ -80,30 +66,11 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": { "scrolled": true }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "1.1415899999999999\n" - ] - }, - { - "ename": "TypeError", - "evalue": "unsupported operand type(s) for -: 'str' and 'str'", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", - "Input \u001b[1;32mIn [2]\u001b[0m, in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[38;5;28mprint\u001b[39m(pi \u001b[38;5;241m-\u001b[39m \u001b[38;5;241m2.0\u001b[39m)\n\u001b[0;32m 4\u001b[0m \u001b[38;5;66;03m# Subtraction with strings\u001b[39;00m\n\u001b[1;32m----> 5\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[43mfitness\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m-\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43ma\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m)\n", - "\u001b[1;31mTypeError\u001b[0m: unsupported operand type(s) for -: 'str' and 'str'" - ] - } - ], + "outputs": [], "source": [ "# Subtraction with floats\n", "print(pi - 2.0)\n", @@ -121,24 +88,15 @@ }, { "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "5.14159\n", - "averagea\n" - ] - } - ], + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "# Addition with floats\n", "print(pi + 2.0)\n", "\n", "# Addition with strings\n", - "print(fitness + 'a')" + "print(shape + '-ing')" ] }, { @@ -152,28 +110,16 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Every variable has a type, but there can be overlap between the kinds of values that can be in each type. For example, we can write a number as either an integer or a string. Python treats these differently, even if to us the value is the same:" + "Every variable has a type, but there can be overlap between the kinds of values that can be in each type. For example, we can write a number as either an integer or a string. Python treats these differently, even if to us the value is the same. Let's take a look at an example below:" ] }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": { "scrolled": true }, - "outputs": [ - { - "ename": "TypeError", - "evalue": "unsupported operand type(s) for -: 'int' and 'str'", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", - "Input \u001b[1;32mIn [4]\u001b[0m, in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m a \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m3\u001b[39m\u001b[38;5;124m'\u001b[39m\n\u001b[0;32m 2\u001b[0m b \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m3\u001b[39m\n\u001b[1;32m----> 4\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[43mb\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m-\u001b[39;49m\u001b[43m \u001b[49m\u001b[43ma\u001b[49m)\n", - "\u001b[1;31mTypeError\u001b[0m: unsupported operand type(s) for -: 'int' and 'str'" - ] - } - ], + "outputs": [], "source": [ "a = '3'\n", "b = 3\n", @@ -185,25 +131,16 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Even though our intention is to do numeric subtraction, the type of `a` is a string, which results in an error. Let's check the type of each variable using `type()`:" + "Even though our intention is to do numeric subtraction, the type of `a` is a string, which results in an error. Let's check the type of each variable using `type()`. What do you predict the types of each variable is?" ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": { "scrolled": true }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "\n" - ] - } - ], + "outputs": [], "source": [ "print(type(b))\n", "print(type(a))" @@ -220,27 +157,9 @@ }, { "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "3\n" - ] - }, - { - "data": { - "text/plain": [ - "int" - ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" - } - ], + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "print(int(a))\n", "type(int(a))" @@ -248,17 +167,9 @@ }, { "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "0\n" - ] - } - ], + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "print(b - int(a))" ] @@ -272,21 +183,9 @@ }, { "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [ - { - "ename": "ValueError", - "evalue": "invalid literal for int() with base 10: 'letters'", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", - "Input \u001b[1;32mIn [9]\u001b[0m, in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;28;43mint\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mletters\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n", - "\u001b[1;31mValueError\u001b[0m: invalid literal for int() with base 10: 'letters'" - ] - } - ], + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "int('letters')" ] @@ -309,18 +208,9 @@ }, { "cell_type": "code", - "execution_count": 10, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Half is 0.5\n", - "Three squared is 9.0\n" - ] - } - ], + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "print('Half is', 1 / 2.0)\n", "print('Three squared is', 3.0 ** 2)" @@ -346,7 +236,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -359,9 +249,9 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Built-in Type Methods\n", + "## Methods\n", "\n", - "Specific types can come with their own methods, which are special functions that operate on that type. These methods are accessed by dot notation: `variable.method()`\n", + "**Methods** are special functions that specifically operate on that type. These methods are accessed by **dot notation**: `variable.method()`\n", "\n", "Documentation for these methods can be accessed with `type.[METHOD_NAME]?`.\n", "\n", @@ -370,7 +260,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -379,77 +269,51 @@ }, { "cell_type": "code", - "execution_count": 14, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'GIRAFFE'" - ] - }, - "execution_count": 14, - "metadata": {}, - "output_type": "execute_result" - } - ], + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ - "giraffe = 'giraffe'\n", - "giraffe.upper()" + "giraffe_variable = 'Giraffe'\n", + "giraffe_variable.upper()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Instead of a variable name, the string itself can also be used." + "What do you think `'Giraffe'.lower()` does? " ] }, { "cell_type": "code", - "execution_count": 15, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 15, - "metadata": {}, - "output_type": "execute_result" - } - ], + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ - "'giraffe'.startswith('gir')" + "'Giraffe'.lower()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Methods can also be chained in a single line, as long as the output of one directly feeds into the input of the next. These lines can be read sequentially left to right. Write out the steps that `giraffe` goes through in the following line. What do you think the final output will be?\n", + "Note that calling the method on a variable name is the same as calling it directly on the value. \n", + "\n", + "**Question:** How would we save the results of this method to save for later?\n", + "\n", + "\n", + "Methods can also be chained in a single line, as long as the output of one directly feeds into the input of the next. These lines can be read sequentially left to right. \n", + "\n", + "Without running the code for now, write out the steps that `giraffe` goes through in the following line. What do you think the final output will be? (**Hint:** use `str.startswith?` to see the documentation for that function) \n", "\n", - "Next, run the code. Does the output match what you expected. If not, go back to each step and figure out what happened differently." + "Next, run the code. Does the output match what you expected? If not, go back to each step and figure out what happened differently." ] }, { "cell_type": "code", - "execution_count": 16, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "False" - ] - }, - "execution_count": 16, - "metadata": {}, - "output_type": "execute_result" - } - ], + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [ "'giraffe'.upper().startswith('gir')" ] @@ -458,7 +322,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "There are many many string functions out there, and it is worth spending a few minutes trying to find the appropriate function to use for a given string problem.\n" + "There are *many many* string functions out there, and it is worth spending a few minutes trying to find the appropriate function to use for a given string problem.\n" ] }, { @@ -467,8 +331,8 @@ "source": [ "## Challenge 2: String Methods\n", "\n", - "1. Use `str.split()` on the following sentences. What is the output?\n", - "2. Use `str.split?` to read the documentation for `str.split()`. What does `sep=` do? Where have we seen `sep=` before?\n", + "1. Use `str.split()` on the following sentences. What is the type of the output? What does it look like the function is doing?\n", + "2. Use `str.split?` to read the documentation for `str.split()`. What does `sep=` do? ( **Bonus:** where have we seen `sep=` before?)\n", "3. Try using `sep='.'`. What is the output?\n", "4. What is the default value of `sep=`?\n", "\n", @@ -477,7 +341,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -489,7 +353,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -504,12 +368,12 @@ "\n", "Let's say we have a bunch of filenames with spaces in them. However, we want to remove spaces `' '` and replace them with underscores `_`. Use the [string methods](https://docs.python.org/3/library/stdtypes.html#string-methods) reference and identify an appropriate method. Use that method to get the result: `\"Firstname_Lastname.csv\"\n", "\n", - "**Bonus**: There are always more than one way to solve a programming problem. How many different ways can you solve the problem above?" + "**Bonus**: There is always more than one way to solve a programming problem. How many different ways can you solve the problem above?" ] }, { "cell_type": "code", - "execution_count": 19, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ diff --git a/lessons/Part1/05_functions.ipynb b/lessons/Part1/05_functions.ipynb index 74530a6..1e4d609 100644 --- a/lessons/Part1/05_functions.ipynb +++ b/lessons/Part1/05_functions.ipynb @@ -23,44 +23,7 @@ "\n", "**Functions** are a core part of programming that allows us to run complex operations over and over without needing to write the code over and over again. **Arguments**, or values passed to a function, allow for us to use functions in more general ways.\n", "\n", - "For example, a (made-up) function `multiply_by_five(2)` may take a single argument 2 and multiply it by five. An alternative function `multiply(2, 5)` may have two arguments, but be more generalizable to other multiplication tasks.\n", - "\n", - "A function may take zero or more arguments.\n", - "\n", - "* `len` takes exactly one.\n", - "* `print` takes zero or more.\n", - "* `round` takes one or two." - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": { - "scrolled": true - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "one two\n" - ] - }, - { - "data": { - "text/plain": [ - "3.142" - ] - }, - "execution_count": 1, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "len('before')\n", - "print('one', 'two')\n", - "round(3.1415, 3)" + "For example, a (made-up) function `multiply_by_five(2)` may take a single argument 2 and multiply it by five. An alternative function `multiply(2, 5)` may have two arguments, but be more generalizable to other multiplication tasks.\n" ] }, { @@ -69,74 +32,30 @@ "source": [ "A function without the proper number of arguments will give an error, which will give some information about what arguments you need for the function to be successful.\n", "\n", - "**Question:** Look at the errors below. From the error message, how many arguments does the function take?" + "**Question:** Look at the error below. From the error message, how many arguments does the function take? What is another way we can identify the number of arguments for a function? (**Bonus:** What does `len()` do?)" ] }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "ename": "TypeError", - "evalue": "len() takes exactly one argument (0 given)", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", - "Input \u001b[1;32mIn [9]\u001b[0m, in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;28;43mlen\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n", - "\u001b[1;31mTypeError\u001b[0m: len() takes exactly one argument (0 given)" - ] - } - ], + "outputs": [], "source": [ "len()" ] }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": {}, - "outputs": [ - { - "ename": "TypeError", - "evalue": "round() takes at most 2 arguments (3 given)", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", - "Input \u001b[1;32mIn [10]\u001b[0m, in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;28;43mround\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m3.14\u001b[39;49m\u001b[43m,\u001b[49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m,\u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m)\u001b[49m\n", - "\u001b[1;31mTypeError\u001b[0m: round() takes at most 2 arguments (3 given)" - ] - } - ], - "source": [ - "round(3.14,1,0)" - ] - }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Below, we call a function without parentheses. What does the output say?" + "Below, we use a function name without parentheses. What does the output say? " ] }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 11, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "round" ] @@ -154,22 +73,14 @@ "source": [ "## Nesting Functions\n", "\n", - "Functions can be nested by placing them inside of each other. In this case, the inner function is evaluated first, followed by outer function(s)." + "Functions can be nested by placing them inside of each other. In this case, the inner function is evaluated first, followed by outer function(s). (**Bonus**: Where have we seen multiple functions put together in a single line before?)" ] }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "3\n" - ] - } - ], + "outputs": [], "source": [ "print(round(3.14))" ] @@ -183,21 +94,9 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "ename": "TypeError", - "evalue": "object of type 'int' has no len()", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", - "Input \u001b[1;32mIn [13]\u001b[0m, in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;28;43mlen\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mround\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m3.14\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n", - "\u001b[1;31mTypeError\u001b[0m: object of type 'int' has no len()" - ] - } - ], + "outputs": [], "source": [ "len(round(3.14))" ] @@ -216,52 +115,13 @@ "**Bonus:** What is the code trying to do? What do you predict the output to be?" ] }, - { - "cell_type": "code", - "execution_count": 16, - "metadata": {}, - "outputs": [ - { - "ename": "SyntaxError", - "evalue": "unexpected EOF while parsing (3071631582.py, line 1)", - "output_type": "error", - "traceback": [ - "\u001b[1;36m Input \u001b[1;32mIn [16]\u001b[1;36m\u001b[0m\n\u001b[1;33m print(max(len('hi', len('hello'))\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m unexpected EOF while parsing\n" - ] - } - ], - "source": [ - "print(max(len('hi', len('hello'))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Argument Types\n", - "\n", - "The type and content of an argument must be compatible with the function.\n", - "* For example, taking the maximum of no inputs - `max()` - is a meaningless.\n", - "* Furthermore, `max()` requires types that are comparable (i.e., strings and ints can't be compared to each other).\n", - "* Trying to predict what the output will be can help catch these kinds of errors early on." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "print(max())" - ] - }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "print(max(1, 'a'))" + "print(max(len('hi', len('hello'))" ] }, { @@ -273,27 +133,16 @@ "Some functions do not require you to enter a value for each argument. In these cases, it will use a **default argument** specified in the function.\n", "\n", "* For example, `round()` will round a number. It accepts two arguments: the number, and the number of decimal places to round off to.\n", - "* By default, it rounds to zero decimal places.\n", + "* By default, it rounds to a whole number.\n", "\n", "**Question:** Where do you think we look to find what the default arguments are?" ] }, { "cell_type": "code", - "execution_count": 18, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "4" - ] - }, - "execution_count": 18, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "round(3.712)" ] @@ -307,20 +156,9 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "3.7" - ] - }, - "execution_count": 19, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "round(3.712, 1)" ] @@ -334,7 +172,7 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -350,49 +188,19 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "3.0" - ] - }, - "execution_count": 21, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "#this works\n", "round(3.000, 2)" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "**Question:** Why does the code below give an error? " - ] - }, { "cell_type": "code", - "execution_count": 24, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "ename": "TypeError", - "evalue": "'float' object cannot be interpreted as an integer", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", - "Input \u001b[1;32mIn [24]\u001b[0m, in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;66;03m#this doesn't\u001b[39;00m\n\u001b[1;32m----> 2\u001b[0m \u001b[38;5;28;43mround\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m2\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m3.000\u001b[39;49m\u001b[43m)\u001b[49m\n", - "\u001b[1;31mTypeError\u001b[0m: 'float' object cannot be interpreted as an integer" - ] - } - ], + "outputs": [], "source": [ "#this doesn't\n", "round(2, 3.000)" @@ -402,42 +210,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "If the arguments are the wrong type you will get a `TypeError`, but if the arguments are the right type in the wrong order, you might get nonsensical results." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Challenge 2: Modular Division\n", - "\n", - "`divmod()` is another built-in Python function that returns two values: (1) the value when you divide `a` by `b`, and (2) the remainder. Use the command `?divmod` for more information.\n", - "\n", - "Let's say we want to divide 16 by 5 using this function. \n", - "\n", - "1. What do you predict the outputs to be?\n", - "2. Run the following line of code. Do the results match your expectations? If not, why?\n", - "3. If necessary, modify the code." - ] - }, - { - "cell_type": "code", - "execution_count": 25, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "(0, 5)" - ] - }, - "execution_count": 25, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "divmod(5, 16)" + "**Note:** If the arguments are the wrong type you will get a `TypeError`, but if the arguments are the right type in the wrong order, you might get nonsensical or otherwise incorrect results." ] }, { @@ -451,24 +224,9 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Help on built-in function round in module builtins:\n", - "\n", - "round(number, ndigits=None)\n", - " Round a number to a given precision in decimal digits.\n", - " \n", - " The return value is an integer if ndigits is omitted or None. Otherwise\n", - " the return value has the same type as the number. ndigits may be negative.\n", - "\n" - ] - } - ], + "outputs": [], "source": [ "help(round)" ] @@ -487,17 +245,9 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "The output of divmod(16, 5) is (3, 1)\n" - ] - } - ], + "outputs": [], "source": [ "output = divmod(16, 5)\n", "print('The output of divmod(16, 5) is', output)" @@ -529,7 +279,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Challenge 3: Nested Functions\n", + "## Challenge 2: Nested Functions\n", "\n", "1. Predict what each of the `print` statements in the program below will print. Run the code. If it doesn't match your expectations, write out each step in the code.\n", "2. Does `max(str(len(rich)), poor)` run or produce an error message?\n", @@ -538,31 +288,15 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "tin\n", - "4\n" - ] - } - ], + "outputs": [], "source": [ "rich = \"gold\"\n", "poor = \"tin\"\n", "print(max(rich, poor))\n", "print(max(len(rich), len(poor)))" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { diff --git a/lessons/Part2/10_custom_functions.ipynb b/lessons/Part1/06_custom_functions.ipynb similarity index 61% rename from lessons/Part2/10_custom_functions.ipynb rename to lessons/Part1/06_custom_functions.ipynb index 843ab60..a4d0688 100644 --- a/lessons/Part2/10_custom_functions.ipynb +++ b/lessons/Part1/06_custom_functions.ipynb @@ -18,39 +18,14 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "We have already used **built-in functions** like `len()` , `sum()`, `pd.DataFrame()`, in our code. These are essentially shortcuts that make it so that we don't need to write many lines of code to accomplish certain tasks. \n", - "\n", - "We didn't technically need these functions to perform these tasks. For example, we can calculate the sum without relying on the function by using a for loop with aggregation:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "numbers = [1, 3, 5, 7]\n", - "\n", - "# Accumulate the numbers\n", - "total = 0\n", - "for number in numbers:\n", - " # Add the current value to the sum of the values\n", - " total = total + number\n", - "print('The sum is', total)\n", - "print('Using the sum function:',sum(numbers))" + "We have already used **functions** like `len()` , `sum()` in our code. These are essentially shortcuts that make it so that we don't need to write many lines of code to accomplish certain tasks. One of the most useful programming structures in Python is to write our own functions with a custom functionality that is specific to our goals." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "However, we don't want to have to use this block of code every single time we'd like to add some numbers up. The function is simpler and easier to read.\n", - "\n", - "This is the motivation for *modularizing* our code. When we have an operation we expect to perform repeatedly, like summing, it's useful to have a function that is specifically built to do this.\n", - "\n", - "The functions we've used so far have been **built-in functions**. Python provided them to us. However, we'll often need to create our own functions. Python has a specific syntax for creating new functions.\n", - "\n", - "Let's take a look at a quick example, creating the `my_sum` function that will perform the sum we just did:" + "Let's take a look at a quick example, creating the a function that will format a date into the M/D/YYYY format:" ] }, { @@ -59,12 +34,9 @@ "metadata": {}, "outputs": [], "source": [ - "def my_sum(list_of_numbers):\n", - " total = 0\n", - " for number in numbers:\n", - " # Add the current value to the sum of the values\n", - " total = total + number\n", - " return total" + "def format_date(day, month, year):\n", + " formatted = str(month) + \"/\" + str(day) + \"/\" + str(year)\n", + " return(formatted)" ] }, { @@ -73,8 +45,7 @@ "metadata": {}, "outputs": [], "source": [ - "print(\"The sum with sum() is:\", sum(numbers))\n", - "print(\"The sum with my_sum() is:\", my_sum(numbers))" + "print(\"The formatted date is:\", format_date(1,2,2022))\n" ] }, { @@ -83,7 +54,7 @@ "source": [ "Functions save us a lot of time, but they aren't black boxes. Rather, we can think of functions as basic building blocks that we expect to use over and over again.\n", "\n", - "Using existing functions from packages, or built-in functions, is generally preferred because it saves time (and effort). For example, we wouldn't write a custom `sum()` function when one already exists. However, when a function doesn't already exist that performs the desired operation, we can write our own custom function.\n", + "Using existing functions from packages, or built-in functions, is generally preferred because it saves time (and effort). For example, we wouldn't write a custom `sum()` function when one already exists. However, when a function doesn't already exist that performs the desired operation, we can write our own function.\n", "\n", "Specifically, a function does three things:\n", "\n", @@ -171,15 +142,50 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Function Arguments\n", + "## Principles of Writing Your Own Functions\n", "\n", - "Function **arguments** or **parameters** are specified when defining a function in the parentheses, separated by commas. \n", + "Function writing is one of the most important skills you can develop as a programmer. However, there is also a lot that can go wrong in the function writing process, leading to time-consuming corrections. Here are some guidelines that can help minimize errors and make the process less painful:\n", "\n", - "These arguments become variables when the function is executed. The variables are assigned the values passed to the function. We do operations based on the arguments, and return the result.\n", + "1. **Plan**\n", + " 1. What is the overall goal of the function? Is there a function that exists already that does the same thing? \n", + " 2. What is going to be the output of the function? (what data type, how many items)?\n", + " 3. What arguments will you need? What pieces of the function do you need to control?\n", + " 4. What are the general steps of the program? This can be written in bullet points or \"pseudocode\".\n", + "2. **Write**\n", + " 1. Start by writing the code without the function wrapper.\n", + " 2. Start small. Write small self-contained blocks of code and put the pieces together. You can also consider sub-functions if it is a particularly complex issue.\n", + " 3. Test each part of the function as it is added. Track the input of the function and how it changes at each step. \n", + " 4. Wrap the code in the function syntax.\n", + "3. **Test**\n", + " 1. Take the function and test *several* cases.\n", + " 2. Before running test cases, form an expectation of the result. \n", + " 3. Test the function. Pay attention to both errors and strange results. Make adjustments to account for new cases.\n", + " 4. Integrate the function with the rest of the code. Are the input arguments the right type? Does the output flow into the rest of the code?" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Let's go through an example of the function development process.\n", "\n", - "Let's look at an example function in which we're performing division.\n", + "Let's say we have a state name (e.g. California) and we want to generate the postal abbreviation for that state (California --> CA).\n", "\n", - "**Question:** What is being divided by what in the following lines of code?" + "1. **Plan**\n", + " 1. Generate two-letter abbreviation for a state\n", + " 2. Input: string of state name\n", + " 3. Output: first two letters of string \n", + " 4. The pseudocode might look like this: \n", + " ``` \n", + " function\n", + " select first two characters in the string\n", + " make upper case\n", + " return\n", + " ```\n", + "\n", + "2. **Write**\n", + "\n", + "Let's start with our example string `California` and select the first two characters in the string using string indexing:" ] }, { @@ -188,20 +194,16 @@ "metadata": {}, "outputs": [], "source": [ - "def divide(x, y):\n", - " return(x / y)\n", - "\n", - "print(divide(4, 6))\n", - "print(divide(6, 4)) " + "ex_state = 'California'\n", + "#select first two\n", + "first_two = ex_state[:2]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "The order of the arguments matter; we got different results because each argument had a different role (numerator and denominator).\n", - "\n", - "You can also pass in **keyword arguments**, where each argument is assigned using a name." + "Now we need to make the letters uppercase (And check the output). " ] }, { @@ -210,62 +212,50 @@ "metadata": {}, "outputs": [], "source": [ - "print(divide(x=4, y=6))\n", - "print(divide(y=6, x=4))" + "first_two.upper()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Are the arguments named appropriately? What does x and y stand for? What could be more clear?\n", - "\n", - "Generally, it's good practice to both use well-named arguments and use them in the same order. This is easier to read." + "Now that we've done the individual steps, we can put it together in the function syntax." ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ - "## Default Arguments\n", - "\n", - "We can also specify **default arguments** in functions. When we provide a default argument, the function will use that value when the user does not pass in a value. Default arguments are specified in the function signature.\n", - "\n", - "An expanded version of the `divide()` function is provided below. What is the additional parameter doing? What will be the output of `divide(24,5)`?" + "def get_state_abbreviation(state):\n", + " first_two = state[:2]\n", + " abbr = first_two.upper()" ] }, { - "cell_type": "code", - "execution_count": null, + "cell_type": "markdown", "metadata": {}, - "outputs": [], "source": [ - "# y has default value equal to 10\n", - "def divide(x, y, z = True):\n", - " if z:\n", - " return(round(x / y))\n", - " else:\n", - " return(x/y)" + "Now let's test this out:" ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ - "We can use default arguments when there are arguments that we will only want to change some of the time. It's good practice to make the default of the argument the item that you will want to use most often.\n", - "\n", - "**Question:** What do you think the best default for the `z` argument above would be? What might be a better name for that argument?" + "print(get_state_abbreviation('California'))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "## Challenge 2: More Errors!\n", + "When we print the result, we get `None`. What step needs to be added? Let's add a statement to our definition above so that we can print the result. \n", "\n", - "Why do the following lines return errors?\n", - "\n", - "**Hint**: Think about what happens inside the function, and how the arguments plug into the function." + "Now that we've got a working example let's test it on more examples:" ] }, { @@ -274,16 +264,19 @@ "metadata": {}, "outputs": [], "source": [ - "divide(z=False,10, 4)" + "get_state_abbreviation(\"Washington\")\n", + "get_state_abbreviation(\"california\")" ] }, { - "cell_type": "code", - "execution_count": null, + "cell_type": "markdown", "metadata": {}, - "outputs": [], "source": [ - "divide(4, y='10')" + "## Challenge 2: Modifying a function \n", + "\n", + "Now let's check our `get_state_abbreviation()` function for `Michigan` and `Minnesota`. What happens in the case where the states have the same first two letters? \n", + "\n", + "Write down a revised plan for the function to account for cases like the above, following the steps outlined in the previous section. Don't worry about writing the code for the function at this point. What additional structures or information might you need in order to accommodate cases like Michigan/Minnesota or Maine/Maryland?\n" ] }, { @@ -292,67 +285,43 @@ "metadata": {}, "outputs": [], "source": [ - "divide(4)" + "#original abbreviating function\n", + "def get_state_abbreviation(state):\n", + " first_two = state[:2]\n", + " abbr = first_two.upper()\n", + " return(abbr)" ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ - "There's a lot of different permutations of arguments in functions, so keeping them organized will be helpful to both yourself and other people interacting with your code." + "# YOUR CODE HERE\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "## Principles of Writing Your Own Functions\n", - "\n", - "Function writing is one of the most important skills you can develop as a programmer. However, there is also a lot that can go wrong in the function writing process, leading to time-consuming corrections. Here are some guidelines that can help minimize errors and make the process less painful:\n", - "\n", - "1. **Plan**\n", - " 1. What is the overall goal of the function? Is there a function that exists already that does the same thing? \n", - " 2. What is going to be the output of the function? (what data type, how many items)?\n", - " 3. What arguments will you need? What pieces of the function do you need to control?\n", - " 4. What are the general steps of the program? This can be written in bullet points or \"pseudocode\".\n", - "2. **Write**\n", - " 1. Start by writing the code without the function wrapper.\n", - " 2. Start small. Write small self-contained blocks of code and put the pieces together. You can also consider sub-functions if it is a particularly complex issue.\n", - " 3. Test each part of the function as it is added. Track the input of the function and how it changes at each step. \n", - " 4. Wrap the code in the function syntax.\n", - "3. **Test**\n", - " 1. Take the function and test *several* cases.\n", - " 2. Before running test cases, form an expectation of the result. \n", - " 3. Test the function. Pay attention to both errors and strange results. Make adjustments to account for new cases.\n", - " 4. Integrate the function with the rest of the code. Are the input arguments the right type? Does the output flow into the rest of the code?" + "## Bonus: Advanced Arguments \n", + "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Let's go through an example of the function development process.\n", + "## Function Arguments\n", "\n", - "Let's say we have a list of filenames from an experiment. Each filename has two parts, a county and a year, separated by an underscore (e.g., `Alameda_2020.csv`). We are interested in parsing these names into to a data frame with two columns, one containing the county (lowercase) and one with the year. \n", + "Function **arguments** or **parameters** are specified when defining a function in the parentheses, separated by commas. \n", "\n", - "1. **Plan**\n", - " 1. Parse a list of strings into two parts.\n", - " 2. Input: list of strings\n", - " 3. Output: a DataFrame with two columns\n", - " 4. The pseudocode might look like this: \n", - " ``` \n", - " function\n", - " for file in filelist:\n", - " split file into parts\n", - " process each part\n", - " append to list\n", - " make a dataframe\n", - " return\n", - " ```\n", + "These arguments become variables when the function is executed. The variables are assigned the values passed to the function. We do operations based on the arguments, and return the result.\n", "\n", - "2. **Write**\n", + "Let's look at an example function in which we're performing division.\n", "\n", - "Let's start with a single file inside the loop. First, we'll test the splitting component of the function on a single file." + "**Question:** What is being divided by what in the following lines of code?" ] }, { @@ -361,60 +330,50 @@ "metadata": {}, "outputs": [], "source": [ - "files = ['Alameda_2020.csv',\n", - " 'Marin_2020.csv',\n", - " 'Contra Costa_2020.csv',\n", - " 'Alameda_2021.csv',\n", - " 'San Francisco_2021.csv']\n", + "def divide(x, y):\n", + " return(x / y)\n", "\n", - "#choose 1 file\n", - "test_file = files[1]" + "print(divide(4, 6))\n", + "print(divide(6, 4)) " ] }, { - "cell_type": "code", - "execution_count": null, + "cell_type": "markdown", "metadata": {}, - "outputs": [], "source": [ - "#split file into parts\n", - "file_parts = test_file.split('.')[0].split('_')\n", - "print(file_parts)" + "The order of the arguments matter; we got different results because each argument had a different role (numerator and denominator).\n", + "\n", + "You can also pass in **keyword arguments**, where each argument is assigned using a name." ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ - "Once we have the parts parsed out, we can do the next step and process each part appropriately. For the county, we want to make it lowercase, and for the year, we can convert it to an integer." + "print(divide(x=4, y=6))\n", + "print(divide(y=6, x=4))" ] }, { - "cell_type": "code", - "execution_count": null, + "cell_type": "markdown", "metadata": {}, - "outputs": [], "source": [ - "file_parts = test_file.split('.')[0].split('_')\n", - "\n", + "Are the arguments named appropriately? What does x and y stand for? What could be more clear?\n", "\n", - "#separate out each piece of information that we need\n", - "county = file_parts[0]\n", - "year = file_parts[1]\n", - "# Lowercase county\n", - "county = county.lower()\n", - "# Convert year to int\n", - "year = int(year)\n", - "# Check output\n", - "print(county)\n", - "print(year)" + "Generally, it's good practice to both use well-named arguments and use them in the same order. This is easier to read." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "The next step is to wrap this bit of code in a for-loop to process all files:" + "## Default Arguments\n", + "\n", + "We can also specify **default arguments** in functions. When we provide a default argument, the function will use that value when the user does not pass in a value. Default arguments are specified in the function signature.\n", + "\n", + "An expanded version of the `divide()` function is provided below. What is the additional parameter doing? What will be the output of `divide(24,5)`?" ] }, { @@ -423,78 +382,32 @@ "metadata": {}, "outputs": [], "source": [ - "files = ['Alameda_2020.csv',\n", - " 'Marin_2020.csv',\n", - " 'Contra Costa_2020.csv',\n", - " 'Alameda_2021.csv',\n", - " 'San Francisco_2021.csv']\n", - "county_list = []\n", - "year_list = []\n", - "\n", - "# Iterate over files\n", - "for file in files:\n", - " \n", - " \n", - " ###This is all the same from before\n", - " file_parts = test_file.split('.')[0].split('_')\n", - " county = file_parts[0]\n", - " year = file_parts[1]\n", - " # Lowercase county\n", - " county = county.lower()\n", - " # Convert year to int\n", - " year = int(year)\n", - " \n", - " \n", - " ### Store outputs in an aggregation variable\n", - " county_list.append(county)\n", - " year_list.append(year)\n", - "# Check outputs\n", - "print(county_list)\n", - "print(year_list)" + "# y has default value equal to 10\n", + "def divide(x, y, z = True):\n", + " if z:\n", + " return(round(x / y))\n", + " else:\n", + " return(x/y)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "What happened? How do we fix it?\n", - "\n", - "\n", - "When we run the code on the whole loop, do you notice anything about the other county names? What might we want to change?\n", + "We can use default arguments when there are arguments that we will only want to change some of the time. It's good practice to make the default of the argument the item that you will want to use most often.\n", "\n", - "Once the full code works, we can do the final steps: convert the output to a DataFrame and place everything into a function." + "**Question:** What do you think the best default for the `z` argument above would be? What might be a better name for that argument?" ] }, { - "cell_type": "code", - "execution_count": null, + "cell_type": "markdown", "metadata": {}, - "outputs": [], "source": [ - "import pandas as pd\n", - "\n", - "def parse_files(filelist): #function header\n", - " \n", - " \n", - " ##all of this is the same\n", - " county_list = []\n", - " year_list = []\n", - " for file in files:\n", - " file_parts = file.split('.')[0].split('_')\n", - " county = file_parts[0]\n", - " year = file_parts[1]\n", - " # Lowercase county\n", - " county = county.lower()\n", - " # Convert year to int\n", - " year = int(year)\n", - " # Store outputs\n", - " county_list.append(county)\n", - " year_list.append(year)\n", - " \n", - " ##add a DataFrame and return statement\n", - " df = pd.DataFrame({'county': county_list,\n", - " 'year': year_list})\n", - " return df" + "## Challenge 3: More Errors!\n", + "\n", + "Why do the following lines return errors?\n", + "\n", + "**Hint**: Think about what happens inside the function, and how the arguments fit into the function." ] }, { @@ -503,34 +416,16 @@ "metadata": {}, "outputs": [], "source": [ - "##Test it on all files\n", - "\n", - "files = ['Alameda_2020.csv',\n", - " 'Marin_2020.csv',\n", - " 'Contra Costa_2020.csv',\n", - " 'Alameda_2021.csv',\n", - " 'San Francisco_2021.csv']\n", - "output = parse_files(files)\n", - "output" + "divide(z=False,10, 4)" ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ - "## Challenge 4: Advanced Conversion Function\n", - "\n", - "Now you will get a chance to practice development function. Let's take our foot-to-meters conversion function from before make it more flexible.\n", - "\n", - "Let's say we want to convert from feet to other units as well. Change the original conversion function to a more generalized version `convert_from_feet(x,unit='meters')` by adding a keyword argument `unit` that defaults to meters. Use if statements within the body of the function to do the appropriate conversion based on this keyword argument and return the value. Choose two additional units to meters (such as inches, miles, or centimeters), and add them to the conversion function.\n", - "\n", - "Follow the steps:\n", - "\n", - "1. Plan your function. \n", - "2. Write your function. \n", - "3. Test the function.\n", - "\n", - "**Bonus**: What if you wanted to convert several values at once? What if you want to convert to several other units at once?" + "divide(4, y='10')" ] }, { @@ -539,19 +434,14 @@ "metadata": {}, "outputs": [], "source": [ - "# Original conversion function\n", - "def convert_feet_to_meters(feet):\n", - " meters = feet * .304\n", - " return(meters)" + "divide(4)" ] }, { - "cell_type": "code", - "execution_count": null, + "cell_type": "markdown", "metadata": {}, - "outputs": [], "source": [ - "# YOUR CODE HERE\n" + "There's a lot of different permutations of arguments in functions, so keeping them organized will be helpful to both yourself and other people interacting with your code." ] } ], diff --git a/lessons/Part2/07_dictionaries_and_dataframes.ipynb b/lessons/Part2/07_dictionaries_and_dataframes.ipynb deleted file mode 100644 index a7ef296..0000000 --- a/lessons/Part2/07_dictionaries_and_dataframes.ipynb +++ /dev/null @@ -1,473 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Python Data Structures: Dictionaries and Data Frames\n", - "\n", - "**Learning Objectives**\n", - "* Introduce dictionaries, and data frames.\n", - "* Practice interacting with and manipulating these data structures.\n", - "\n", - "Dictionaries and DataFrames are two other key types of data structure. We will cover each of these in the sections below.\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Dictionaries: Key-Value Structures\n", - "\n", - "Dictionaries are organized on the principle of key-value pairs. The **keys** can be used to access the **values**. They're most useful when you have unordered data organized in pairs. This occurs, for example, in storing metadata (data describing other data).\n", - "\n", - "Keys can be ints, floats, or strings, and are unordered. Values, however, can be any data type.\n", - "\n", - "Dictionaries are specified in Python using curly braces, with colons separating keys and values. \n", - "\n", - "Let's take a look at an example dictionary:" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "1935" - ] - }, - "execution_count": 1, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "example_dict = {\n", - " \"name\": \"Forough Farrokhzad\",\n", - " \"year of birth\": 1935,\n", - " \"year of death\": 1967,\n", - " \"place of birth\": \"Iran\",\n", - " \"language\": \"Persian\"}\n", - "\n", - "example_dict['year of birth']" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Like lists, dictionaries have their own methods. One of them is the `keys()` method. What is the type of the output of `.keys()`?" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "dict_keys(['name', 'year of birth', 'year of death', 'place of birth', 'language'])\n" - ] - }, - { - "data": { - "text/plain": [ - "dict_keys" - ] - }, - "execution_count": 2, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "print(example_dict.keys())\n", - "type(example_dict.keys())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "`dict_keys` is a type that we haven't encountered before, so it will be hard to work with this type directly. However, recall that we can use type conversion to change the type of a variable. We can **cast** (or change the type of) the dictionary keys to a list, which is a type that we are more familiar with:" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "['name', 'year of birth', 'year of death', 'place of birth', 'language']" - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "list(example_dict.keys())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Challenge 1: Creating a Dictionary\n", - "\n", - "Create a dictionary `fruits` with the following lists. Use the names of each list for the keys of the dictionary. Print the list of keys of the dictionary." - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [], - "source": [ - "fruit = ['apple', 'orange', 'mango']\n", - "length = [3.2, 2.1, 3.1]\n", - "color = ['red', 'orange', 'yellow']\n", - "\n", - "\n", - "\n", - "# YOUR CODE HERE" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Dictionaries are useful for hierarchical storage of data (and can even be nested just like lists!). They are also often used to initialize data frames, a useful data structure for tabular data, and essential for data scientists." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Data Frames\n", - "\n", - "A common data structure you've likely already encountered is tabular data. Think of an Excel sheet: each column corresponds to a different feature of each datapoint, while rows correspond to different samples.\n", - "\n", - "In scientific programming, tabular data is often called a \"data frame\". In Python, there a specialized library called `pandas` which contains an object `DataFrame` that implements this data structure.\n", - "\n", - "We're going to explore `pandas` more closely in Part 3, but let's try creating a `DataFrame` object right now. \n", - "\n", - "\n", - "First, we need to create a dictionary:\n", - "\n", - "**Note:** You can also substitute in your answer for Challenge 1 below." - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [], - "source": [ - "fruit = ['apple', 'orange', 'mango', 'strawberry', 'salmonberry', 'thimbleberry']\n", - "size = [3, 2, 3, 1, 1, 1]\n", - "color = ['red', 'orange', 'orange', 'red', 'orange', 'red']\n", - "\n", - "fruits = {\n", - " 'fruit': fruit,\n", - " 'size': size,\n", - " 'color': color}" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Next, we import the `pandas` **library** (We will cover libraries in more detail in Part 3) and pass in the dictionary to the `pd.DataFrame()` function, storing the result in a variable called `df`." - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
fruitsizecolor
0apple3red
1orange2orange
2mango3orange
3strawberry1red
4salmonberry1orange
5thimbleberry1red
\n", - "
" - ], - "text/plain": [ - " fruit size color\n", - "0 apple 3 red\n", - "1 orange 2 orange\n", - "2 mango 3 orange\n", - "3 strawberry 1 red\n", - "4 salmonberry 1 orange\n", - "5 thimbleberry 1 red" - ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "import pandas as pd\n", - "\n", - "df = pd.DataFrame(fruits)\n", - "df" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The keys became column names and the values became cells in the `DataFrame`. In addition, there is an **index** on the left that keeps track of the row.\n", - "\n", - "Objects can also have **attributes**, or variables associated with the data type. We can get the number of columns and rows with `df.shape`, an attribute of the dataframe. \n", - "\n", - "**Question:** How many rows and columns does this dataframe have? " - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "(6, 3)" - ] - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "df.shape" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Challenge 2: Initializing a DataFrame\n", - "\n", - "The following code gives an error. Why does it have an error? What are some ways to fix this?" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": {}, - "outputs": [ - { - "ename": "ValueError", - "evalue": "All arrays must be of the same length", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", - "Input \u001b[1;32mIn [10]\u001b[0m, in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 3\u001b[0m color \u001b[38;5;241m=\u001b[39m [\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mred\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124morange\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124myellow\u001b[39m\u001b[38;5;124m'\u001b[39m]\n\u001b[0;32m 5\u001b[0m fruit_dict \u001b[38;5;241m=\u001b[39m {\n\u001b[0;32m 6\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mfruit\u001b[39m\u001b[38;5;124m'\u001b[39m: fruit,\n\u001b[0;32m 7\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mlength\u001b[39m\u001b[38;5;124m'\u001b[39m: length,\n\u001b[0;32m 8\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mcolor\u001b[39m\u001b[38;5;124m'\u001b[39m: color}\n\u001b[1;32m---> 10\u001b[0m df_fruit \u001b[38;5;241m=\u001b[39m \u001b[43mpd\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mDataFrame\u001b[49m\u001b[43m(\u001b[49m\u001b[43mfruit_dict\u001b[49m\u001b[43m)\u001b[49m\n", - "File \u001b[1;32m~\\anaconda32022\\lib\\site-packages\\pandas\\core\\frame.py:636\u001b[0m, in \u001b[0;36mDataFrame.__init__\u001b[1;34m(self, data, index, columns, dtype, copy)\u001b[0m\n\u001b[0;32m 630\u001b[0m mgr \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_init_mgr(\n\u001b[0;32m 631\u001b[0m data, axes\u001b[38;5;241m=\u001b[39m{\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mindex\u001b[39m\u001b[38;5;124m\"\u001b[39m: index, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcolumns\u001b[39m\u001b[38;5;124m\"\u001b[39m: columns}, dtype\u001b[38;5;241m=\u001b[39mdtype, copy\u001b[38;5;241m=\u001b[39mcopy\n\u001b[0;32m 632\u001b[0m )\n\u001b[0;32m 634\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(data, \u001b[38;5;28mdict\u001b[39m):\n\u001b[0;32m 635\u001b[0m \u001b[38;5;66;03m# GH#38939 de facto copy defaults to False only in non-dict cases\u001b[39;00m\n\u001b[1;32m--> 636\u001b[0m mgr \u001b[38;5;241m=\u001b[39m \u001b[43mdict_to_mgr\u001b[49m\u001b[43m(\u001b[49m\u001b[43mdata\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mindex\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcolumns\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdtype\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mdtype\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcopy\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcopy\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtyp\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mmanager\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 637\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(data, ma\u001b[38;5;241m.\u001b[39mMaskedArray):\n\u001b[0;32m 638\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mnumpy\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mma\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mmrecords\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01mmrecords\u001b[39;00m\n", - "File \u001b[1;32m~\\anaconda32022\\lib\\site-packages\\pandas\\core\\internals\\construction.py:502\u001b[0m, in \u001b[0;36mdict_to_mgr\u001b[1;34m(data, index, columns, dtype, typ, copy)\u001b[0m\n\u001b[0;32m 494\u001b[0m arrays \u001b[38;5;241m=\u001b[39m [\n\u001b[0;32m 495\u001b[0m x\n\u001b[0;32m 496\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28mhasattr\u001b[39m(x, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mdtype\u001b[39m\u001b[38;5;124m\"\u001b[39m) \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(x\u001b[38;5;241m.\u001b[39mdtype, ExtensionDtype)\n\u001b[0;32m 497\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m x\u001b[38;5;241m.\u001b[39mcopy()\n\u001b[0;32m 498\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m x \u001b[38;5;129;01min\u001b[39;00m arrays\n\u001b[0;32m 499\u001b[0m ]\n\u001b[0;32m 500\u001b[0m \u001b[38;5;66;03m# TODO: can we get rid of the dt64tz special case above?\u001b[39;00m\n\u001b[1;32m--> 502\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43marrays_to_mgr\u001b[49m\u001b[43m(\u001b[49m\u001b[43marrays\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mcolumns\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mindex\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mdtype\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mdtype\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtyp\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mtyp\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mconsolidate\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcopy\u001b[49m\u001b[43m)\u001b[49m\n", - "File \u001b[1;32m~\\anaconda32022\\lib\\site-packages\\pandas\\core\\internals\\construction.py:120\u001b[0m, in \u001b[0;36marrays_to_mgr\u001b[1;34m(arrays, columns, index, dtype, verify_integrity, typ, consolidate)\u001b[0m\n\u001b[0;32m 117\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m verify_integrity:\n\u001b[0;32m 118\u001b[0m \u001b[38;5;66;03m# figure out the index, if necessary\u001b[39;00m\n\u001b[0;32m 119\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m index \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m--> 120\u001b[0m index \u001b[38;5;241m=\u001b[39m \u001b[43m_extract_index\u001b[49m\u001b[43m(\u001b[49m\u001b[43marrays\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 121\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m 122\u001b[0m index \u001b[38;5;241m=\u001b[39m ensure_index(index)\n", - "File \u001b[1;32m~\\anaconda32022\\lib\\site-packages\\pandas\\core\\internals\\construction.py:674\u001b[0m, in \u001b[0;36m_extract_index\u001b[1;34m(data)\u001b[0m\n\u001b[0;32m 672\u001b[0m lengths \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mlist\u001b[39m(\u001b[38;5;28mset\u001b[39m(raw_lengths))\n\u001b[0;32m 673\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(lengths) \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m1\u001b[39m:\n\u001b[1;32m--> 674\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mAll arrays must be of the same length\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m 676\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m have_dicts:\n\u001b[0;32m 677\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\n\u001b[0;32m 678\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mMixing dicts with non-Series may lead to ambiguous ordering.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 679\u001b[0m )\n", - "\u001b[1;31mValueError\u001b[0m: All arrays must be of the same length" - ] - } - ], - "source": [ - "fruit = ['apple', 'orange']\n", - "length = [3.2, 2.1, 3.1]\n", - "color = ['red', 'orange', 'yellow']\n", - "\n", - "fruit_dict = {\n", - " 'fruit': fruit,\n", - " 'length': length,\n", - " 'color': color}\n", - "\n", - "df_fruit = pd.DataFrame(fruit_dict)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Working with DataFrames\n", - "\n", - "Pandas has hundreds of useful ways for us to work with DataFrames. We will cover a couple of general topics here and in Part 3, but for more on pandas, consider the Python Data Wrangling workshop. \n", - "\n", - "\n", - "We can choose a single column by selecting the name of that column. `pandas` calls this a `pd.Series` object. The act of obtaining a particular subset of a data frame is often referred to as **slicing**. This uses bracket notation to select part of the data.\n", - "\n", - "Check the type of the slice below:" - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "metadata": { - "scrolled": false - }, - "outputs": [ - { - "data": { - "text/plain": [ - "0 apple\n", - "1 orange\n", - "2 mango\n", - "3 strawberry\n", - "4 salmonberry\n", - "5 thimbleberry\n", - "Name: fruit, dtype: object" - ] - }, - "execution_count": 14, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Bracket notation to choose a column\n", - "df['fruit']" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "`DataFrame` objects also have methods, including those for [merging](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.merge.html?highlight=merge#pandas.DataFrame.merge), [aggregation](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.groupby.html), [nulls](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.groupby.html), and others. Many of these functions operate on a single column of the DataFrame. For example, we can identify the number of unique values in each column by using `.nunique()`, and what those unique values are by using `.unique()`:" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "2\n", - "['red' 'orange']\n" - ] - } - ], - "source": [ - "#number of unique colors in the df\n", - "print(df['color'].nunique())\n", - "\n", - "\n", - "#unique colors in the df\n", - "print(df['color'].unique())" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Challenge 3: `value_counts()`\n", - "\n", - "There is another pandas function `.value_counts()` which can be used to help organize the information provided by `unique()`. Read the [documentation](https://pandas.pydata.org/docs/reference/api/pandas.Series.value_counts.html) and apply `value_counts()` to the `df` variable. How many 'red' and 'orange' fruits are in the DataFrame?" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "## YOUR CODE HERE." - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.9.12" - } - }, - "nbformat": 4, - "nbformat_minor": 4 -} diff --git a/lessons/Part2/06_lists.ipynb b/lessons/Part2/07_lists.ipynb similarity index 100% rename from lessons/Part2/06_lists.ipynb rename to lessons/Part2/07_lists.ipynb diff --git a/lessons/Part2/08_dictionaries_and_dataframes.ipynb b/lessons/Part2/08_dictionaries_and_dataframes.ipynb new file mode 100644 index 0000000..63bf492 --- /dev/null +++ b/lessons/Part2/08_dictionaries_and_dataframes.ipynb @@ -0,0 +1,298 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Python Data Structures: Dictionaries and Data Frames\n", + "\n", + "**Learning Objectives**\n", + "* Introduce dictionaries, and data frames.\n", + "* Practice interacting with and manipulating these data structures.\n", + "\n", + "Dictionaries and DataFrames are two other key types of data structure. We will cover each of these in the sections below.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Dictionaries: Key-Value Structures\n", + "\n", + "Dictionaries are organized on the principle of key-value pairs. The **keys** can be used to access the **values**. They're most useful when you have unordered data organized in pairs. This occurs, for example, in storing metadata (data describing other data).\n", + "\n", + "Keys can be ints, floats, or strings, and are unordered. Values, however, can be any data type.\n", + "\n", + "Dictionaries are specified in Python using curly braces, with colons separating keys and values. \n", + "\n", + "Let's take a look at an example dictionary:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "example_dict = {\n", + " \"name\": \"Forough Farrokhzad\",\n", + " \"year of birth\": 1935,\n", + " \"year of death\": 1967,\n", + " \"place of birth\": \"Iran\",\n", + " \"language\": \"Persian\"}\n", + "\n", + "example_dict['year of birth']" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Like lists, dictionaries have their own methods. One of them is the `keys()` method. What is the type of the output of `.keys()`?" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "print(example_dict.keys())\n", + "type(example_dict.keys())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "`dict_keys` is a type that we haven't encountered before, so it will be hard to work with this type directly. However, recall that we can use type conversion to change the type of a variable. We can **cast** (or change the type of) the dictionary keys to a list, which is a type that we are more familiar with:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "list(example_dict.keys())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Challenge 1: Creating a Dictionary\n", + "\n", + "Create a dictionary `fruits` using the following lists as *values*. Choose an appropriate string for each of the *keys* of the dictionary. Print the keys in the dictionary." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "fruit = ['apple', 'orange', 'mango']\n", + "length = [3.2, 2.1, 3.1]\n", + "color = ['red', 'orange', 'yellow']\n", + "\n", + "\n", + "\n", + "# YOUR CODE HERE" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Dictionaries are useful for hierarchical storage of data (and can even be nested just like lists!). They are also often used to initialize data frames, a useful data structure for tabular data, and essential for data scientists." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Data Frames\n", + "\n", + "A common data structure you've likely already encountered is tabular data. Think of an Excel sheet: each column corresponds to a different feature of each datapoint, while rows correspond to different samples.\n", + "\n", + "In scientific programming, tabular data is often called a \"data frame\". In Python, there a specialized library called `pandas` which contains an object `DataFrame` that implements this data structure.\n", + "\n", + "We're going to explore `pandas` more closely in Part 3, but let's try creating a `DataFrame` object right now. \n", + "\n", + "\n", + "First, we need to create a dictionary:\n", + "\n", + "**Note:** You can also substitute in your answer for Challenge 1 below." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "fruit = ['apple', 'orange', 'mango', 'strawberry', 'salmonberry', 'thimbleberry']\n", + "size = [3, 2, 3, 1, 1, 1]\n", + "color = ['red', 'orange', 'orange', 'red', 'orange', 'red']\n", + "\n", + "fruits = {\n", + " 'fruit': fruit,\n", + " 'size': size,\n", + " 'color': color}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Next, we import the `pandas` **library** (We will cover libraries in more detail in Part 3) and pass in the dictionary to the `pd.DataFrame()` function, storing the result in a variable called `df`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd\n", + "\n", + "df = pd.DataFrame(fruits)\n", + "df" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The keys became column names and the values became cells in the `DataFrame`. In addition, there is an **index** on the left that keeps track of the row.\n", + "\n", + "Objects can also have **attributes**, or variables associated with the data type. We can get the number of columns and rows with `df.shape`, an attribute of the dataframe. \n", + "\n", + "**Question:** How many rows and columns does this dataframe have? " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "df.shape" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Challenge 2: Initializing a DataFrame\n", + "\n", + "The following code gives an error. Why does it have an error? What are some ways to fix this?" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "fruit = ['apple', 'orange']\n", + "length = [3.2, 2.1, 3.1]\n", + "color = ['red', 'orange', 'yellow']\n", + "\n", + "fruit_dict = {\n", + " 'fruit': fruit,\n", + " 'length': length,\n", + " 'color': color}\n", + "\n", + "df_fruit = pd.DataFrame(fruit_dict)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Working with DataFrames\n", + "\n", + "Pandas has hundreds of useful ways for us to work with DataFrames. We will cover a couple of general topics here and in Part 3, but for more on pandas, consider the Python Data Wrangling workshop. \n", + "\n", + "\n", + "We can choose a single column by selecting the name of that column. `pandas` calls this a `pd.Series` object. The act of obtaining a particular subset of a data frame is often referred to as **slicing**. This uses bracket notation to select part of the data.\n", + "\n", + "Check the type of the slice below:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "scrolled": false + }, + "outputs": [], + "source": [ + "# Bracket notation to choose a column\n", + "df['fruit']" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "`DataFrame` objects also have methods, including those for [merging](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.merge.html?highlight=merge#pandas.DataFrame.merge), [aggregation](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.groupby.html), [nulls](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.groupby.html), and others. Many of these functions operate on a single column of the DataFrame. For example, we can identify the number of unique values in each column by using `.nunique()`, and what those unique values are by using `.unique()`:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#number of unique colors in the df\n", + "print(df['color'].nunique())\n", + "\n", + "\n", + "#unique colors in the df\n", + "print(df['color'].unique())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Challenge 3: `value_counts()`\n", + "\n", + "There is another pandas function `.value_counts()` which can be used to help organize the information provided by `unique()`. Read the [documentation](https://pandas.pydata.org/docs/reference/api/pandas.Series.value_counts.html) and apply `value_counts()` to the `df` variable. How many 'red' and 'orange' fruits are in the DataFrame?" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "## YOUR CODE HERE." + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.12" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/lessons/Part2/08_loops.ipynb b/lessons/Part2/09_loops.ipynb similarity index 98% rename from lessons/Part2/08_loops.ipynb rename to lessons/Part2/09_loops.ipynb index 30db703..17f08fb 100644 --- a/lessons/Part2/08_loops.ipynb +++ b/lessons/Part2/09_loops.ipynb @@ -296,8 +296,8 @@ "total = 0\n", "words = [\"red\", \"green\", \"blue\"]\n", "\n", - "for word in words:\n", - " ____ = ____ + len(word)\n", + "for w in words:\n", + " ____ = ____ + len(w)\n", "\n", "print(total)" ] @@ -318,7 +318,7 @@ "lengths = ____\n", "words = [\"red\", \"green\", \"blue\"]\n", "\n", - "for word in words:\n", + "for w in words:\n", " lengths.____(____)\n", "\n", "print(lengths)" @@ -384,9 +384,9 @@ "pets = ['cat', 'dog', 'hamster', 'iguana']\n", "\n", "# Iterate over pets\n", - "for pet in pets:\n", + "for p in pets:\n", " # Iterate over each letter in a pet\n", - " for letter in pet:\n", + " for letter in p:\n", " print(letter)" ] }, diff --git a/lessons/Part2/09_conditionals.ipynb b/lessons/Part2/10_conditionals.ipynb similarity index 97% rename from lessons/Part2/09_conditionals.ipynb rename to lessons/Part2/10_conditionals.ipynb index 3a063b2..1603db2 100644 --- a/lessons/Part2/09_conditionals.ipynb +++ b/lessons/Part2/10_conditionals.ipynb @@ -429,23 +429,6 @@ "The order of the if and elif statements matters. When one if/elif statement is met, all following statements are skipped. If there are multiple if statements, then each statement is evaluated separately. These kinds of errors won't give errors in the code, but they will give results that might not make sense, which can take longer to find and debug." ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "original = [-1.5, 0.2, 0.4, 0.0, -1.3, 0.4]\n", - "result = ____\n", - "\n", - "for value in original:\n", - " if ____:\n", - " result.append(0)\n", - " else:\n", - " ____\n", - "print(result)" - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -523,13 +506,6 @@ " ____.append(___)\n", "print(last_name_b)" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { diff --git a/lessons/Part3/11_libraries.ipynb b/lessons/Part3/11_libraries.ipynb index 549601c..8913203 100644 --- a/lessons/Part3/11_libraries.ipynb +++ b/lessons/Part3/11_libraries.ipynb @@ -104,7 +104,7 @@ "\n", "* `pandas` -> `pd`\n", "* `numpy` -> `np`\n", - "* `matplotlib` -> `mpl`.\n", + "* `matplotlib` -> `mpl`\n", "* `statsmodels.api` -> `sm`\n", "\n", "But sometimes aliases can make programs harder to understand, since readers must learn your program's aliases. Be very intentional about using aliases!" diff --git a/lessons/Part3/12_file_io.ipynb b/lessons/Part3/12_file_io.ipynb index a7240b0..a9e0d92 100644 --- a/lessons/Part3/12_file_io.ipynb +++ b/lessons/Part3/12_file_io.ipynb @@ -42,11 +42,11 @@ "metadata": {}, "outputs": [], "source": [ - "#open file\n", + "# Open file\n", "my_file = open(\"capitals.csv\", \"r\") \n", - "#read file\n", + "# Read file\n", "text = my_file.read()\n", - "#close file\n", + "# Close file\n", "my_file.close()\n", "\n", "print(text)" @@ -254,22 +254,22 @@ "df_list = []\n", "\n", "\n", - "##get list of files\n", + "## Get list of files\n", "# YOUR CODE HERE\n", "\n", - "##loop through each file\n", + "## Loop through each file\n", "# YOUR CODE HERE\n", "\n", - " ## read in each file\n", + " ## Read in each file\n", " # YOUR CODE HERE\n", "\n", - " ## append dataframe to the list\n", + " ## Append dataframe to the list\n", " # YOUR CODE HERE\n", "\n", "\n", "\n", "\n", - "#output should be a list of data_frames saved to df_list" + "# Output should be a list of data_frames saved to df_list" ] }, { diff --git a/lessons/Part3/13_pandas.ipynb b/lessons/Part3/13_pandas.ipynb index 9c2e15d..dc66fe4 100644 --- a/lessons/Part3/13_pandas.ipynb +++ b/lessons/Part3/13_pandas.ipynb @@ -104,7 +104,7 @@ "source": [ "A single column of pandas is a `Series` object. This can be treated as a list or other iterable, and allows for you to do calculations over it. \n", "\n", - "We can then look at the [documentation](https://pandas.pydata.org/docs/reference/api/pandas.Series.html) to see the methods and attributes that are available for `Series` objects. If we want the median, we can ue the `.median()` function." + "We can then look at the [documentation](https://pandas.pydata.org/docs/reference/api/pandas.Series.html) to see the methods and attributes that are available for `Series` objects. If we want the median, we can use the `.median()` function." ] }, { @@ -146,7 +146,7 @@ "\n", "A variation on this is an operation containing two columns. Let's say we want to take the ratio of the culmen length and depth for all of the penguins.\n", "\n", - "**Question:** The code below has two error in it. What is it trying to do, and how do you fix it?" + "**Question:** The code below has two errors in it. What is it trying to do, and how do you fix it?" ] }, { @@ -211,7 +211,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "There are easily several hundred methods asociated with `DataFrames` and `Series`. There are a handful of very common ones that get used frequently, but often there will be some functions that are more specific to your interest. For this reason, more important than memorizing functions, is learning how to do something. " + "There are easily several hundred methods asociated with `DataFrames` and `Series`. For this reason, it is impractical to try to memorize every function and its arguments. Rather, it is often more productive to focus on developing (1) an understanding of what is possible with Python and (2) the ability to learn how to implement new functions by reading documentation, examples, etc." ] }, { diff --git a/lessons/Part3/14_statsmodels.ipynb b/lessons/Part3/14_statsmodels.ipynb index 0659c63..5a09a86 100644 --- a/lessons/Part3/14_statsmodels.ipynb +++ b/lessons/Part3/14_statsmodels.ipynb @@ -182,7 +182,7 @@ "metadata": {}, "outputs": [], "source": [ - "print(results.summary())" + "print(result.summary())" ] }, { diff --git a/lessons/Part4/15_errors.ipynb b/lessons/Part4/15_errors.ipynb index a17a58c..43a6a55 100644 --- a/lessons/Part4/15_errors.ipynb +++ b/lessons/Part4/15_errors.ipynb @@ -32,22 +32,9 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "ename": "TypeError", - "evalue": "unsupported operand type(s) for /: 'int' and 'str'", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", - "Input \u001b[1;32mIn [2]\u001b[0m, in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mrandom_function\u001b[39m(x, y):\n\u001b[0;32m 2\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m(x \u001b[38;5;241m/\u001b[39m y)\n\u001b[1;32m----> 3\u001b[0m \u001b[43mrandom_function\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m12\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m14\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n", - "Input \u001b[1;32mIn [2]\u001b[0m, in \u001b[0;36mrandom_function\u001b[1;34m(x, y)\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mrandom_function\u001b[39m(x, y):\n\u001b[1;32m----> 2\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m(\u001b[43mx\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m/\u001b[39;49m\u001b[43m \u001b[49m\u001b[43my\u001b[49m)\n", - "\u001b[1;31mTypeError\u001b[0m: unsupported operand type(s) for /: 'int' and 'str'" - ] - } - ], + "outputs": [], "source": [ "def random_function(x, y):\n", " return(x / y)\n", @@ -109,23 +96,9 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "ename": "AttributeError", - "evalue": "'list' object has no attribute 'split'", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)", - "Input \u001b[1;32mIn [4]\u001b[0m, in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mparse_titles\u001b[39m(titles): \n\u001b[0;32m 5\u001b[0m split_and_lower(titles)\n\u001b[1;32m----> 7\u001b[0m \u001b[43mparse_titles\u001b[49m\u001b[43m(\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mKafka on the Shore\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mNorwegian Woods\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m)\u001b[49m\n", - "Input \u001b[1;32mIn [4]\u001b[0m, in \u001b[0;36mparse_titles\u001b[1;34m(titles)\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mparse_titles\u001b[39m(titles): \n\u001b[1;32m----> 5\u001b[0m \u001b[43msplit_and_lower\u001b[49m\u001b[43m(\u001b[49m\u001b[43mtitles\u001b[49m\u001b[43m)\u001b[49m\n", - "Input \u001b[1;32mIn [4]\u001b[0m, in \u001b[0;36msplit_and_lower\u001b[1;34m(string)\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21msplit_and_lower\u001b[39m(string):\n\u001b[1;32m----> 2\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m(\u001b[43mstring\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msplit\u001b[49m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m \u001b[39m\u001b[38;5;124m'\u001b[39m)\u001b[38;5;241m.\u001b[39mlower())\n", - "\u001b[1;31mAttributeError\u001b[0m: 'list' object has no attribute 'split'" - ] - } - ], + "outputs": [], "source": [ "def split_and_lower(string):\n", " return(string.split(' ').lower())\n", @@ -150,7 +123,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, "metadata": { "attributes": { "classes": [ @@ -159,16 +132,7 @@ "id": "" } }, - "outputs": [ - { - "ename": "SyntaxError", - "evalue": "invalid syntax (2123195529.py, line 1)", - "output_type": "error", - "traceback": [ - "\u001b[1;36m Input \u001b[1;32mIn [5]\u001b[1;36m\u001b[0m\n\u001b[1;33m def some_function()\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n" - ] - } - ], + "outputs": [], "source": [ "def some_function()\n", " msg = \"hello, world!\"\n", @@ -191,7 +155,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, "metadata": { "attributes": { "classes": [ @@ -200,16 +164,7 @@ "id": "" } }, - "outputs": [ - { - "ename": "IndentationError", - "evalue": "unexpected indent (2087495754.py, line 4)", - "output_type": "error", - "traceback": [ - "\u001b[1;36m Input \u001b[1;32mIn [6]\u001b[1;36m\u001b[0m\n\u001b[1;33m return msg\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mIndentationError\u001b[0m\u001b[1;31m:\u001b[0m unexpected indent\n" - ] - } - ], + "outputs": [], "source": [ "def some_function():\n", " msg = \"hello, world!\"\n", @@ -248,7 +203,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, "metadata": { "attributes": { "classes": [ @@ -257,19 +212,7 @@ "id": "" } }, - "outputs": [ - { - "ename": "NameError", - "evalue": "name 'a' is not defined", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", - "Input \u001b[1;32mIn [8]\u001b[0m, in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[43ma\u001b[49m)\n", - "\u001b[1;31mNameError\u001b[0m: name 'a' is not defined" - ] - } - ], + "outputs": [], "source": [ "print(a)" ] @@ -313,7 +256,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "metadata": { "attributes": { "classes": [ @@ -322,28 +265,7 @@ "id": "" } }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "a\n", - "b\n", - "c\n" - ] - }, - { - "ename": "IndexError", - "evalue": "list index out of range", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mIndexError\u001b[0m Traceback (most recent call last)", - "Input \u001b[1;32mIn [10]\u001b[0m, in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m letters \u001b[38;5;241m=\u001b[39m [\u001b[38;5;124m'\u001b[39m\u001b[38;5;124ma\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mb\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mc\u001b[39m\u001b[38;5;124m'\u001b[39m]\n\u001b[0;32m 3\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m i \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mrange\u001b[39m(\u001b[38;5;241m4\u001b[39m):\n\u001b[1;32m----> 4\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[43mletters\u001b[49m\u001b[43m[\u001b[49m\u001b[43mi\u001b[49m\u001b[43m]\u001b[49m)\n", - "\u001b[1;31mIndexError\u001b[0m: list index out of range" - ] - } - ], + "outputs": [], "source": [ "letters = ['a', 'b', 'c']\n", "\n", @@ -375,23 +297,11 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "metadata": { "scrolled": true }, - "outputs": [ - { - "ename": "TypeError", - "evalue": "unsupported operand type(s) for +: 'int' and 'str'", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", - "Input \u001b[1;32mIn [11]\u001b[0m, in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m a \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m2\u001b[39m\u001b[38;5;124m'\u001b[39m\n\u001b[0;32m 2\u001b[0m b \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m15\u001b[39m\n\u001b[1;32m----> 4\u001b[0m \u001b[43mb\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[43ma\u001b[49m\n", - "\u001b[1;31mTypeError\u001b[0m: unsupported operand type(s) for +: 'int' and 'str'" - ] - } - ], + "outputs": [], "source": [ "a = '2'\n", "b = 15\n", @@ -425,21 +335,9 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "ename": "AttributeError", - "evalue": "'float' object has no attribute 'split'", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)", - "Input \u001b[1;32mIn [12]\u001b[0m, in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;241;43m3.14\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msplit\u001b[49m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m.\u001b[39m\u001b[38;5;124m'\u001b[39m)\n", - "\u001b[1;31mAttributeError\u001b[0m: 'float' object has no attribute 'split'" - ] - } - ], + "outputs": [], "source": [ "3.14.split('.')" ] @@ -500,18 +398,9 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "ename": "SyntaxError", - "evalue": "invalid syntax (372945126.py, line 4)", - "output_type": "error", - "traceback": [ - "\u001b[1;36m Input \u001b[1;32mIn [13]\u001b[1;36m\u001b[0m\n\u001b[1;33m for word in t.split(' ')\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n" - ] - } - ], + "outputs": [], "source": [ "def make_acronyms(titles):\n", " acronym = ''\n", diff --git a/lessons/Part4/16_style.ipynb b/lessons/Part4/16_style.ipynb index 7568ff4..575e466 100644 --- a/lessons/Part4/16_style.ipynb +++ b/lessons/Part4/16_style.ipynb @@ -36,20 +36,9 @@ }, { "cell_type": "code", - "execution_count": 20, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "96.8 %\n", - "79.0 %\n", - "86.9 %\n", - "99.0 %\n" - ] - } - ], + "outputs": [], "source": [ "import numpy as np\n", "\n", @@ -58,20 +47,12 @@ "\n", "for prop in proportion_list:\n", " \n", - " # convert from percent to proportion\n", " percent = prop * 100 #multiply by 100\n", " percent = round(percent,1)\n", " print(percent,'%')\n", "\n" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Inaccurate comments can be misleading in the future. So keep them up to date! When you make changes, make sure the comments are consistent with the code." - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -84,7 +65,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -106,7 +87,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ diff --git a/lessons/Part4/17_project.ipynb b/lessons/Part4/17_project.ipynb index 1139327..668afcb 100644 --- a/lessons/Part4/17_project.ipynb +++ b/lessons/Part4/17_project.ipynb @@ -89,10 +89,10 @@ "metadata": {}, "outputs": [], "source": [ - "#extract filename from path\n", + "# Extract filename from path\n", "filename = 'airline_data/Delta.csv'.split('/')[1] \n", "print(filename)\n", - "#fill in the blanks\n", + "# Fill in the blanks\n", "name = filename.split(___)[___]\n", "\n", "single_airline['airline'] = name" @@ -113,7 +113,7 @@ "source": [ "def process_file(filepath):\n", " df = pd.read_csv(filepath)\n", - " #add code to extract airline name and save it to a name variable\n", + " # Add code to extract airline name and save it to a name variable\n", " name = ___\n", " df['airline'] = name\n", " return(df)" @@ -161,7 +161,7 @@ "source": [ "directory = 'airline_data'\n", "for file in os.____(____):\n", - " print(___)\n" + " print(______)\n" ] }, { @@ -180,10 +180,10 @@ "metadata": {}, "outputs": [], "source": [ - "test_csv='delta.csv' #expression should evaluate True\n", - "test_txt='delta.txt' # evaluate false\n", + "test_csv='delta.csv' # Expression should evaluate True\n", + "test_txt='delta.txt' # Evaluate false\n", "\n", - "#Test both files" + "# Test both files" ] }, { @@ -203,7 +203,7 @@ "source": [ "directory = 'airline_data'\n", "for file in os.listdir(directory):\n", - " if _____ #fill in the blank to filter for files ending with `.csv`\n", + " if _____ # Fill in the blank to filter for files ending with `.csv`\n", " print(file)" ] }, @@ -234,7 +234,7 @@ "source": [ "directory = 'airline_data'\n", "for file in os.listdir(directory):\n", - " if _____: #fill in the blank to filter for files ending with `.csv`\n", + " if _____: # Fill in the blank to filter for files ending with `.csv`\n", " process_file(file)" ] }, @@ -452,7 +452,7 @@ "pos_neg_df = df.loc[____]\n", "\n", "\n", - "##calculate the proportion positive sentiment tweets\n", + "# Calculate the proportion positive sentiment tweets\n", "\n" ] }, @@ -520,7 +520,7 @@ "metadata": {}, "outputs": [], "source": [ - "#Your code here!" + "# YOUR CODE HERE" ] }, { diff --git a/solutions/03_variables_solutions.ipynb b/solutions/03_variables_solutions.ipynb index e69e8a2..05b2763 100644 --- a/solutions/03_variables_solutions.ipynb +++ b/solutions/03_variables_solutions.ipynb @@ -2,6 +2,7 @@ "cells": [ { "cell_type": "markdown", + "id": "617b8eae", "metadata": {}, "source": [ "## Challenge 1: Debugging Variable Names\n", @@ -11,18 +12,10 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, + "id": "1b2388da", "metadata": {}, - "outputs": [ - { - "ename": "SyntaxError", - "evalue": "invalid syntax (, line 2)", - "output_type": "error", - "traceback": [ - "\u001b[0;36m File \u001b[0;32m\"\"\u001b[0;36m, line \u001b[0;32m2\u001b[0m\n\u001b[0;31m 1a = 'Washington'\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n" - ] - } - ], + "outputs": [], "source": [ "# First variable starts with a number, names are uninformative\n", "1a = 'Washington'\n", @@ -32,17 +25,10 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": null, + "id": "1dc91ffc", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "The capital of Washington is Olympia\n" - ] - } - ], + "outputs": [], "source": [ "# Solution\n", "state = 'Washington'\n", @@ -52,17 +38,10 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, + "id": "efc1f01e", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "924\n" - ] - } - ], + "outputs": [], "source": [ "# Python is case sensitive, inconsistent formatting\n", "A_variable = 22\n", @@ -72,17 +51,10 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, + "id": "edfa16e5", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "924\n" - ] - } - ], + "outputs": [], "source": [ "# Solution\n", "a_variable = 22\n", @@ -92,52 +64,10 @@ }, { "cell_type": "markdown", + "id": "99ce8c22", "metadata": {}, "source": [ - "## Challenge 2: Words to Code\n", - "\n", - "Translate the following clause into code and save the result to a variable. \n", - "\n", - "Divide 15 by the sum of a and three times b. Multiply the result by 2 and raise it to the 3rd power. What is the result? \n", - "\n", - "**Hint**: Order of operations applies in Python (i.e., PEMDAS)." - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [], - "source": [ - "a = 2\n", - "b = 3" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "20.285499624342595" - ] - }, - "execution_count": 10, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "((15 / (a + 3 * b)) * 2)**3" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Challenge 3: Swapping Values\n", + "## Challenge 2: Swapping Values\n", "\n", "Let's say we have two variables and we want to swap the values for each of them. \n", "\n", @@ -146,18 +76,10 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, + "id": "addc1bed", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "z\n", - "z\n" - ] - } - ], + "outputs": [], "source": [ "first = 'a'\n", "last = 'z'\n", @@ -175,18 +97,10 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": null, + "id": "b80d152c", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "z\n", - "a\n" - ] - } - ], + "outputs": [], "source": [ "#solution\n", "first = 'a'\n", @@ -204,6 +118,7 @@ { "cell_type": "code", "execution_count": null, + "id": "ef29e458", "metadata": {}, "outputs": [], "source": [] @@ -211,7 +126,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -225,7 +140,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.6" + "version": "3.9.12" } }, "nbformat": 4, diff --git a/solutions/04_data_types_solutions.ipynb b/solutions/04_data_types_solutions.ipynb index e2e9940..f01c2c9 100644 --- a/solutions/04_data_types_solutions.ipynb +++ b/solutions/04_data_types_solutions.ipynb @@ -2,6 +2,7 @@ "cells": [ { "cell_type": "markdown", + "id": "0ab7f9a3", "metadata": {}, "source": [ "## Challenge 1: String to integer\n", @@ -11,20 +12,10 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": null, + "id": "db26f995", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "3" - ] - }, - "execution_count": 6, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "pi = '3.14'\n", "int(float(pi))\n", @@ -34,179 +25,104 @@ }, { "cell_type": "markdown", + "id": "5a79aa91", "metadata": {}, "source": [ "## Challenge 2: String Methods\n", "\n", - "Use `str.split?` to read the documentation for `str.split()`. Use `str.split()` on the following sentences. What happens? What does `sep=` do? Try using `sep='.'`. \n", + "1. Use `str.split()` on the following sentences. What is the type of the output? What does it look like the function is doing?\n", + "2. Use `str.split?` to read the documentation for `str.split()`. What does `sep=` do? ( **Bonus:** where have we seen `sep=` before?)\n", + "3. Try using `sep='.'`. Compare the output to that in Question 1\n", + "4. What would you set `sep` equal to to get the same output as Question 1?\n", "\n", "**Bonus**: What is the type of the output?" ] }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, + "id": "1fd45798", "metadata": {}, "outputs": [], "source": [ "str.split?\n", "sentence1 = 'There is a giraffe. There is an elephant.'\n", - "sentence2 = 'They are playing chess.'\n", - "sentence3 = 'The elephant is winning. However, the giraffe can make a comeback.'" + "sentence2 = 'They are playing chess.'" ] }, { "cell_type": "code", - "execution_count": 8, + "execution_count": null, + "id": "93fb7cba", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "['There', 'is', 'a', 'giraffe.', 'There', 'is', 'an', 'elephant.']" - ] - }, - "execution_count": 8, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ - "str.split(sentence1)" + "sentence1.split()" ] }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, + "id": "e8846035", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "['They', 'are', 'playing', 'chess.']" - ] - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ - "str.split(sentence2)" + "sentence2.split()" ] }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, + "id": "1e1818e9", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "['The',\n", - " 'elephant',\n", - " 'is',\n", - " 'winning.',\n", - " 'However,',\n", - " 'the',\n", - " 'giraffe',\n", - " 'can',\n", - " 'make',\n", - " 'a',\n", - " 'comeback.']" - ] - }, - "execution_count": 10, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ - "str.split(sentence3)" + "print(type(sentence1.split()))" ] }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, + "id": "7264fdc9", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "['There is a giraffe', ' There is an elephant', '']" - ] - }, - "execution_count": 11, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ - "str.split(sentence1, sep='.')" + "sentence1.split(sep='.')" ] }, { "cell_type": "code", - "execution_count": 12, + "execution_count": null, + "id": "c2d0b608", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "['They are playing chess', '']" - ] - }, - "execution_count": 12, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ - "str.split(sentence2, sep='.')" + "sentence1.split(sep='.')" ] }, { "cell_type": "code", - "execution_count": 13, + "execution_count": null, + "id": "41dd0e37", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "['The elephant is winning', ' However, the giraffe can make a comeback', '']" - ] - }, - "execution_count": 13, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ - "str.split(sentence3, sep='.')" + "sentence1.split(sep=' ')" ] }, { "cell_type": "code", - "execution_count": 14, + "execution_count": null, + "id": "cbcc577e", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "list" - ] - }, - "execution_count": 14, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ - "type(str.split(sentence3, sep='.'))" + "sentence1.split(sep=' ')" ] }, { "cell_type": "markdown", + "id": "88a4146a", "metadata": {}, "source": [ "## Challenge 3: Replacing a character\n" @@ -214,20 +130,10 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": null, + "id": "0e16f623", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'Firstname_Lastname.csv'" - ] - }, - "execution_count": 16, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "# One solution\n", "sentence4 = \"Firstname Lastname.csv\"\n", @@ -237,7 +143,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -251,7 +157,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.6" + "version": "3.9.12" } }, "nbformat": 4, diff --git a/solutions/05_functions_solutions.ipynb b/solutions/05_functions_solutions.ipynb index 304bfbc..1213e7c 100644 --- a/solutions/05_functions_solutions.ipynb +++ b/solutions/05_functions_solutions.ipynb @@ -2,26 +2,28 @@ "cells": [ { "cell_type": "markdown", + "id": "3a3d6169", "metadata": {}, "source": [ "## Challenge 1: Errors in Nested Functions\n", "\n", "\n", - "What doe sthe following line of code do?\n", + "What does the following line of code do?\n", "Running this code gives an error. What type of error is it? How can we fix it?" ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 1, + "id": "d045e209", "metadata": {}, "outputs": [ { "ename": "SyntaxError", - "evalue": "unexpected EOF while parsing (, line 2)", + "evalue": "unexpected EOF while parsing (3622155098.py, line 2)", "output_type": "error", "traceback": [ - "\u001b[0;36m File \u001b[0;32m\"\"\u001b[0;36m, line \u001b[0;32m2\u001b[0m\n\u001b[0;31m print(max(len('hi'), len('hello'))\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m unexpected EOF while parsing\n" + "\u001b[1;36m Input \u001b[1;32mIn [1]\u001b[1;36m\u001b[0m\n\u001b[1;33m print(max(len('hi'), len('hello'))\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m unexpected EOF while parsing\n" ] } ], @@ -32,7 +34,8 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 2, + "id": "8878ee7a", "metadata": {}, "outputs": [ { @@ -49,65 +52,10 @@ }, { "cell_type": "markdown", + "id": "f12414fd", "metadata": {}, "source": [ - "## Challenge 2: Modular Division\n", - "\n", - "`divmod()` is another built-in Python function that returns two values: (1) the value when you divide `a` by `b`, and (2) the remainder. Use the command `?divmod` for more information.\n", - "\n", - "Let's say we want to divide 16 by 5 using this function. \n", - "\n", - "1. What do you predict the output to be?\n", - "2. Run the following line of code. Do the results match your expectations? If not, why?\n", - "3. If necessary, modify the code." - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "(0, 5)" - ] - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "divmod(5, 16)" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "(3, 1)" - ] - }, - "execution_count": 10, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# We need to switch the order to get 16 divided by 5\n", - "divmod(16, 5)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Challenge 3: Nested Functions\n", + "## Challenge 2: Nested Functions\n", "\n", "1. Predict what each of the `print` statements in the program below will print.\n", "2. Does `max(str(len(rich)), poor)` run or produce an error message?\n", @@ -116,18 +64,10 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": null, + "id": "5057be01", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "tin\n", - "4\n" - ] - } - ], + "outputs": [], "source": [ "rich = \"gold\"\n", "poor = \"tin\"\n", @@ -139,20 +79,10 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": null, + "id": "8ca16c6c", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'tin'" - ] - }, - "execution_count": 19, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "#comparing alphanumeric strings have the order '0-9A-Za-z', even for number strings\n", "max(str(len(rich)), poor)" @@ -161,6 +91,7 @@ { "cell_type": "code", "execution_count": null, + "id": "00fee0e5", "metadata": {}, "outputs": [], "source": [] @@ -168,7 +99,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -182,7 +113,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.6" + "version": "3.9.12" } }, "nbformat": 4, diff --git a/solutions/10_custom_functions.ipynb b/solutions/06_custom_functions.ipynb similarity index 67% rename from solutions/10_custom_functions.ipynb rename to solutions/06_custom_functions.ipynb index 9ef2077..accbaf8 100644 --- a/solutions/10_custom_functions.ipynb +++ b/solutions/06_custom_functions.ipynb @@ -34,7 +34,59 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Challenge 2: More Errors!\n", + "## Challenge 2: Modifying a function \n", + "\n", + "Now let's check our `get_state_abbreviation()` function for `Michigan` and `Minnesota`. What happens in the case where the states have the same first two letters? \n", + "\n", + "Write down a revised plan for the function to account for cases like the above, following the steps outlined in the previous section. Don't worry about writing the code for the function at this point- the goal is to think broadly about what we would need to build a function to accomplish our goal. What additional structures or information might you need in order to accommodate cases like Michigan/Minnesota or Maine/Maryland?" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#original abbreviating function\n", + "def get_state_abbreviation(state):\n", + " first_two = state[:2]\n", + " abbr = first_two.upper()\n", + " return(abbr)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# YOUR CODE HERE\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + " **Plan**\n", + " 1. Generate two-letter abbreviation for a state\n", + " 2. Input: string of state name\n", + " 3. Output: two letter abbreviation based on \n", + " USPS abbreviation scheme\n", + " 4. The pseudocode might look like this: \n", + " \n", + " function\n", + " \n", + " select abbreviation from a list of abbreviations organized alphabetically\n", + " \n", + " return\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Challenge 3: More Errors!\n", "\n", "Why do the following lines return errors?\n", "\n", @@ -113,60 +165,6 @@ "#solution\n", "divide(4,10)" ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Challenge 3: Advanced Conversion Function\n", - "\n", - "Let's take our conversion function from before make it more flexible.\n", - "\n", - "Let's say we want to convert from feet to other units as well. Change the original conversion function to a more generalized version `convert_from_feet(x,unit='meters')` by adding a keyword argument `unit` that defaults to meters. Use if statements within the body of the function to do the appropriate conversion based on this keyword argument and return the value. Choose two additional units to meters (such as inches, miles, or centimeters), and add them to the conversion function.\n", - "\n", - "\n", - "\n", - "Follow the steps:\n", - "\n", - "1. Plan your function. \n", - "2. Write your function. \n", - "3. Test the function.\n", - "\n", - "**Bonus**: What if you wanted to convert several values at once? What if you want to convert to several other units at once?" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "def convert_from_feet(x,unit='meters'):\n", - " if unit=='meters':\n", - " return(x*.308)\n", - " elif unit == 'inches':\n", - " return(x*12)\n", - " elif unit == 'yards':\n", - " return(x*3)\n", - " else:\n", - " return('unit not found')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "convert_from_feet(6,unit='inches')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { diff --git a/solutions/06_lists.ipynb b/solutions/07_lists.ipynb similarity index 100% rename from solutions/06_lists.ipynb rename to solutions/07_lists.ipynb diff --git a/solutions/07_dictionaries_and_dataframes.ipynb b/solutions/08_dictionaries_and_dataframes.ipynb similarity index 95% rename from solutions/07_dictionaries_and_dataframes.ipynb rename to solutions/08_dictionaries_and_dataframes.ipynb index 816f95c..7305d84 100644 --- a/solutions/07_dictionaries_and_dataframes.ipynb +++ b/solutions/08_dictionaries_and_dataframes.ipynb @@ -6,7 +6,7 @@ "source": [ "## Challenge 1: Creating a Dictionary\n", "\n", - "Create a dictionary `fruits` with the following lists. Print the list of keys in the dictionary." + "Create a dictionary `fruits` using the following lists as *values*. Choose an appropriate string for each of the *keys* of the dictionary. Print the keys in the dictionary." ] }, { diff --git a/solutions/08_loops.ipynb b/solutions/09_loops.ipynb similarity index 100% rename from solutions/08_loops.ipynb rename to solutions/09_loops.ipynb diff --git a/solutions/09_conditionals.ipynb b/solutions/10_conditionals.ipynb similarity index 100% rename from solutions/09_conditionals.ipynb rename to solutions/10_conditionals.ipynb diff --git a/solutions/11_libraries.ipynb b/solutions/11_libraries.ipynb index 66d8e1d..9a8a750 100644 --- a/solutions/11_libraries.ipynb +++ b/solutions/11_libraries.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Challenge 2: Locating the Right Library\n", + "## Challenge 1: Locating the Right Library\n", "\n", "You want to select a random value from your data.\n", "\n", diff --git a/solutions/13_pandas.ipynb b/solutions/13_pandas.ipynb index fbf7a57..c105c18 100644 --- a/solutions/13_pandas.ipynb +++ b/solutions/13_pandas.ipynb @@ -9,23 +9,9 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "Chinstrap 68\n", - "Gentoo 124\n", - "Adelie 152\n", - "Name: species, dtype: int64" - ] - }, - "execution_count": 25, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "import pandas as pd\n", "import numpy as np\n", @@ -37,190 +23,9 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
speciesislandculmen_length_mmculmen_depth_mmflipper_length_mmbody_mass_gsex
0FalseFalseFalseFalseFalseFalseFalse
1FalseFalseFalseFalseFalseFalseFalse
2FalseFalseFalseFalseFalseFalseFalse
3FalseFalseTrueTrueTrueTrueTrue
4FalseFalseFalseFalseFalseFalseFalse
........................
339FalseFalseTrueTrueTrueTrueTrue
340FalseFalseFalseFalseFalseFalseFalse
341FalseFalseFalseFalseFalseFalseFalse
342FalseFalseFalseFalseFalseFalseFalse
343FalseFalseFalseFalseFalseFalseFalse
\n", - "

344 rows × 7 columns

\n", - "
" - ], - "text/plain": [ - " species island culmen_length_mm culmen_depth_mm flipper_length_mm \\\n", - "0 False False False False False \n", - "1 False False False False False \n", - "2 False False False False False \n", - "3 False False True True True \n", - "4 False False False False False \n", - ".. ... ... ... ... ... \n", - "339 False False True True True \n", - "340 False False False False False \n", - "341 False False False False False \n", - "342 False False False False False \n", - "343 False False False False False \n", - "\n", - " body_mass_g sex \n", - "0 False False \n", - "1 False False \n", - "2 False False \n", - "3 True True \n", - "4 False False \n", - ".. ... ... \n", - "339 True True \n", - "340 False False \n", - "341 False False \n", - "342 False False \n", - "343 False False \n", - "\n", - "[344 rows x 7 columns]" - ] - }, - "execution_count": 26, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "penguins.isnull()\n", "#operates on the dataframe\n", @@ -229,190 +34,9 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
speciesislandculmen_length_mmculmen_depth_mmflipper_length_mmbody_mass_gsex
0AdelieTorgersen39.118.7181.03750.0MALE
1AdelieTorgersen39.517.4186.03800.0FEMALE
2AdelieTorgersen40.318.0195.03250.0FEMALE
4AdelieTorgersen36.719.3193.03450.0FEMALE
5AdelieTorgersen39.320.6190.03650.0MALE
........................
338GentooBiscoe47.213.7214.04925.0FEMALE
340GentooBiscoe46.814.3215.04850.0FEMALE
341GentooBiscoe50.415.7222.05750.0MALE
342GentooBiscoe45.214.8212.05200.0FEMALE
343GentooBiscoe49.916.1213.05400.0MALE
\n", - "

334 rows × 7 columns

\n", - "
" - ], - "text/plain": [ - " species island culmen_length_mm culmen_depth_mm flipper_length_mm \\\n", - "0 Adelie Torgersen 39.1 18.7 181.0 \n", - "1 Adelie Torgersen 39.5 17.4 186.0 \n", - "2 Adelie Torgersen 40.3 18.0 195.0 \n", - "4 Adelie Torgersen 36.7 19.3 193.0 \n", - "5 Adelie Torgersen 39.3 20.6 190.0 \n", - ".. ... ... ... ... ... \n", - "338 Gentoo Biscoe 47.2 13.7 214.0 \n", - "340 Gentoo Biscoe 46.8 14.3 215.0 \n", - "341 Gentoo Biscoe 50.4 15.7 222.0 \n", - "342 Gentoo Biscoe 45.2 14.8 212.0 \n", - "343 Gentoo Biscoe 49.9 16.1 213.0 \n", - "\n", - " body_mass_g sex \n", - "0 3750.0 MALE \n", - "1 3800.0 FEMALE \n", - "2 3250.0 FEMALE \n", - "4 3450.0 FEMALE \n", - "5 3650.0 MALE \n", - ".. ... ... \n", - "338 4925.0 FEMALE \n", - "340 4850.0 FEMALE \n", - "341 5750.0 MALE \n", - "342 5200.0 FEMALE \n", - "343 5400.0 MALE \n", - "\n", - "[334 rows x 7 columns]" - ] - }, - "execution_count": 27, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "penguins.dropna()\n", "#operates on the dataframe\n" @@ -420,31 +44,9 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "0 A\n", - "1 A\n", - "2 A\n", - "3 A\n", - "4 A\n", - " ..\n", - "339 G\n", - "340 G\n", - "341 G\n", - "342 G\n", - "343 G\n", - "Name: species, Length: 344, dtype: object" - ] - }, - "execution_count": 28, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "penguins['species'].str[0]\n", "#operates on a column\n", @@ -462,7 +64,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -484,33 +86,11 @@ }, { "cell_type": "code", - "execution_count": 35, + "execution_count": null, "metadata": { "scrolled": true }, - "outputs": [ - { - "data": { - "text/plain": [ - "0 1\n", - "1 0\n", - "2 0\n", - "3 2\n", - "4 0\n", - " ..\n", - "339 2\n", - "340 0\n", - "341 1\n", - "342 0\n", - "343 1\n", - "Name: sex, Length: 344, dtype: object" - ] - }, - "execution_count": 35, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "penguins['sex'].replace(['MALE','FEMALE',np.nan],[1,0,2])\n", "#Replaces nulls with 2. Might have issues in the model (since 2 doesn't represent a third category)" @@ -518,202 +98,9 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
speciesislandculmen_length_mmculmen_depth_mmflipper_length_mmbody_mass_gsexsex_numeric
0AdelieTorgersen39.118.7181.03750.0MALE1
1AdelieTorgersen39.517.4186.03800.0FEMALE0
2AdelieTorgersen40.318.0195.03250.0FEMALE0
3AdelieTorgersen2.02.02.02.022
4AdelieTorgersen36.719.3193.03450.0FEMALE0
...........................
339GentooBiscoe2.02.02.02.022
340GentooBiscoe46.814.3215.04850.0FEMALE0
341GentooBiscoe50.415.7222.05750.0MALE1
342GentooBiscoe45.214.8212.05200.0FEMALE0
343GentooBiscoe49.916.1213.05400.0MALE1
\n", - "

344 rows × 8 columns

\n", - "
" - ], - "text/plain": [ - " species island culmen_length_mm culmen_depth_mm flipper_length_mm \\\n", - "0 Adelie Torgersen 39.1 18.7 181.0 \n", - "1 Adelie Torgersen 39.5 17.4 186.0 \n", - "2 Adelie Torgersen 40.3 18.0 195.0 \n", - "3 Adelie Torgersen 2.0 2.0 2.0 \n", - "4 Adelie Torgersen 36.7 19.3 193.0 \n", - ".. ... ... ... ... ... \n", - "339 Gentoo Biscoe 2.0 2.0 2.0 \n", - "340 Gentoo Biscoe 46.8 14.3 215.0 \n", - "341 Gentoo Biscoe 50.4 15.7 222.0 \n", - "342 Gentoo Biscoe 45.2 14.8 212.0 \n", - "343 Gentoo Biscoe 49.9 16.1 213.0 \n", - "\n", - " body_mass_g sex sex_numeric \n", - "0 3750.0 MALE 1 \n", - "1 3800.0 FEMALE 0 \n", - "2 3250.0 FEMALE 0 \n", - "3 2.0 2 2 \n", - "4 3450.0 FEMALE 0 \n", - ".. ... ... ... \n", - "339 2.0 2 2 \n", - "340 4850.0 FEMALE 0 \n", - "341 5750.0 MALE 1 \n", - "342 5200.0 FEMALE 0 \n", - "343 5400.0 MALE 1 \n", - "\n", - "[344 rows x 8 columns]" - ] - }, - "execution_count": 38, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "penguins.fillna(2)\n", "\n", @@ -723,202 +110,9 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
speciesislandculmen_length_mmculmen_depth_mmflipper_length_mmbody_mass_gsexsex_numeric
0AdelieTorgersen39.118.7181.03750.0MALE1
1AdelieTorgersen39.517.4186.03800.0FEMALE0
2AdelieTorgersen40.318.0195.03250.0FEMALE0
4AdelieTorgersen36.719.3193.03450.0FEMALE0
5AdelieTorgersen39.320.6190.03650.0MALE1
...........................
338GentooBiscoe47.213.7214.04925.0FEMALE0
340GentooBiscoe46.814.3215.04850.0FEMALE0
341GentooBiscoe50.415.7222.05750.0MALE1
342GentooBiscoe45.214.8212.05200.0FEMALE0
343GentooBiscoe49.916.1213.05400.0MALE1
\n", - "

334 rows × 8 columns

\n", - "
" - ], - "text/plain": [ - " species island culmen_length_mm culmen_depth_mm flipper_length_mm \\\n", - "0 Adelie Torgersen 39.1 18.7 181.0 \n", - "1 Adelie Torgersen 39.5 17.4 186.0 \n", - "2 Adelie Torgersen 40.3 18.0 195.0 \n", - "4 Adelie Torgersen 36.7 19.3 193.0 \n", - "5 Adelie Torgersen 39.3 20.6 190.0 \n", - ".. ... ... ... ... ... \n", - "338 Gentoo Biscoe 47.2 13.7 214.0 \n", - "340 Gentoo Biscoe 46.8 14.3 215.0 \n", - "341 Gentoo Biscoe 50.4 15.7 222.0 \n", - "342 Gentoo Biscoe 45.2 14.8 212.0 \n", - "343 Gentoo Biscoe 49.9 16.1 213.0 \n", - "\n", - " body_mass_g sex sex_numeric \n", - "0 3750.0 MALE 1 \n", - "1 3800.0 FEMALE 0 \n", - "2 3250.0 FEMALE 0 \n", - "4 3450.0 FEMALE 0 \n", - "5 3650.0 MALE 1 \n", - ".. ... ... ... \n", - "338 4925.0 FEMALE 0 \n", - "340 4850.0 FEMALE 0 \n", - "341 5750.0 MALE 1 \n", - "342 5200.0 FEMALE 0 \n", - "343 5400.0 MALE 1 \n", - "\n", - "[334 rows x 8 columns]" - ] - }, - "execution_count": 39, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "penguins.dropna(subset = 'sex')\n", "#This drops all rows with NAN in the sex column. This is the most straightforward option.\n", @@ -937,7 +131,7 @@ }, { "cell_type": "code", - "execution_count": 40, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -952,7 +146,7 @@ "source": [ "## Challenge 4: Customizing a Plot\n", "\n", - "One intuition may be that different penguin species have different culemtn length/depth, resulting in the pattern observed in the scatterplot above. Let's say we want to explore this pattern by plotting the data for each species in a different color. This will allow us to visualize this pattern if is present.\n", + "One intuition may be that different penguin species have different culmen length/depth, resulting in the pattern observed in the scatterplot above. Let's say we want to explore this pattern by plotting the data for each species in a different color. This will allow us to visualize this pattern if it is present in the data.\n", "\n", "The way we implement this in plotting is by plotting individual layers for each species. Most visualizations treat images as \"layers\" on the backend. This allows us to create customizations to plots pretty easily, because each customization would be a new \"layer\".\n", "\n", @@ -972,39 +166,19 @@ }, { "cell_type": "code", - "execution_count": 41, + "execution_count": null, "metadata": {}, - "outputs": [ - { - "data": { - "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX8AAAEHCAYAAABGNUbLAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAABARUlEQVR4nO2de5xcZZH3f9U93TOdmUwSw8AGQjKuiHIREnJRjIvcfReRoIvRKDczii6GBbygu/uKrJeP4g1UXBUJLwFlloBKuLguBhDURTIDSUgCuiI7IRckQ0xCZjLTM91d7x+nz8zp08+59rl1d30/n6GnT5/znDo9pJ56quqpImaGIAiC0Fyk4hZAEARBiB5R/oIgCE2IKH9BEIQmRJS/IAhCEyLKXxAEoQlpiVsAtxxyyCHc3d0dtxiCIAh1xVNPPfUKM3eZj9eN8u/u7kZ/f3/cYgiCINQVRLRNdVzcPoIgCE2IKH9BEIQmJHTlT0TTiegeIvoDET1HRCcT0WuI6FdE9Kfy64yw5RAEQRAmicLy/zaAXzLzGwGcCOA5AJ8F8DAzvx7Aw+X3giAIQkSEqvyJqBPAKQBWAQAzjzHzPgBLAawun7YawPlhyiEIgiBUErbl/7cABgH8PyLaQES3EFE7gMOY+SUAKL8eqrqYiC4jon4i6h8cHAxZVEEoMzgI9PVpr4LQoISt/FsAnATg+8w8H8AwPLh4mPlmZl7IzAu7uqrSVAUheHp7gblzgbPO0l57e+OWSBBCIWzlvwPADmZ+svz+HmiTwctENAsAyq+7Q5ZDEJwZHAR6eoCREWD/fu21p0dWAEJDEqryZ+a/ANhORG8oHzoDwLMA7gNwSfnYJQD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z81sBXA7gVmYeAPADADcw8zxm/o1HOQBA/47eBG2iO5qZFwO4BZOTCaBVSj0dWiXQ+6H1lTgOwJuIaJ7DPYQGRix/ISmcDuAeveZR2Vp3e+2j5aYeB4hoPzQlB2jW8Anl0r9vBXC3YcxWw/X3MnMJwLNEdJjNfU4B0MvMRQC7iEivPfQGaBPQr8rjpwG8ZLiut/xMjxNRJxFNtxjfrRwA0KfXrieiPwN4yPDMpxnOu5+ZmYg2A3iZmTeXr9kKoBvaqkRoQkT5C0mBUN3lrIDy6rTscslaXJs3/F4yvC9B+388BWBfuQWi0/VOM46qGBYB2MrMJ7u8xqqglhc5nJ7ZfF5JcY38+29ixO0jJIWHASwjopmA1owbwACABeXPlwLI+Bm43Ojjf4noveWxiYhO9DHU4wDeT0Tpcr143cL+I4AuIjq5PH6m7MbSeV/5+NsA7Gfm/QAOAJjq53kEIQhE+QuJgJm3QvOTP0ZEm6AFT38E4O1EtB7AmwEM13CLDwLoKY+9Fdpk4pWfQ6ujvxnA9wE8VpZ9DMAFAK4vj78RlZk8e4nov6H5+XvKx+4H8G4i2khEf+dDFkGoCSnpLAghUs72+RQz98ctiyAYEctfEAShCRHLXxBMENGboHUWM5Jn5jc3oxxCYyLKXxAEoQkRt48gCEITIspfEAShCRHlLwiC0ISI8hcEQWhC/j/JPTSoOqas1wAAAABJRU5ErkJggg==\n", - "text/plain": [ - "
" - ] - }, - "metadata": { - "needs_background": "light" - }, - "output_type": "display_data" - } - ], + "outputs": [], "source": [ "adelie = penguins.loc[penguins['species']=='Adelie',:]\n", "chinstrap = penguins.loc[penguins['species']=='Chinstrap',:]\n", "gentoo = penguins.loc[penguins['species']=='Gentoo',:]\n", "\n", "\n", - "ax = adelie.plot(x='culmen_depth_mm',y='culmen_length_mm',kind = 'scatter')\n", - "ax = gentoo.plot(x='culmen_depth_mm',y='culmen_length_mm',kind = 'scatter',color='red',ax=ax)\n", - "ax = chinstrap.plot(x='culmen_depth_mm',y='culmen_length_mm',kind = 'scatter',color='green',ax=ax)" + "fig = adelie.plot(x='culmen_depth_mm',y='culmen_length_mm',kind = 'scatter')\n", + "gentoo.plot(x='culmen_depth_mm',y='culmen_length_mm',kind = 'scatter',color='red',ax=fig)\n", + "chinstrap.plot(x='culmen_depth_mm',y='culmen_length_mm',kind = 'scatter',color='green',ax=fig)" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { From a68afb9dd36e7a1333a31a7e5c84830000083af1 Mon Sep 17 00:00:00 2001 From: Emily Grabowski Date: Mon, 7 Nov 2022 11:27:18 -0800 Subject: [PATCH 2/3] Update README.md Change reference to workshop_setup.ipynb to be the new location in the repo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 22c176a..e21e810 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ Now that you have all the required software and materials, you need to run the c 2. Click the "Launch" button under "Jupyter Notebooks" and navigate through your file system to the `Python-Fundamentals` folder you downloaded above. -3. Open the `lessons` folder, then `Part1`, and open `00_workshop_setup.ipynb` to begin. +3. In the folder, open the `00_workshop_setup.ipynb` to begin. 4. Press Shift + Enter (or Ctrl + Enter) to run a cell. From 90e16c9036b91b56d4788566a2b6fc2d643174e7 Mon Sep 17 00:00:00 2001 From: Pratik Sachdeva Date: Fri, 6 Jan 2023 14:30:42 -0800 Subject: [PATCH 3/3] README updates (#91) * update readme buttons, text, style changes * remove period --- README.md | 146 ++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 108 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index e21e810..bf19a32 100644 --- a/README.md +++ b/README.md @@ -1,82 +1,152 @@ -# D-Lab's Python Fundamentals Workshop +# D-Lab Python Fundamentals Workshop -[![Datahub](https://img.shields.io/badge/launch-datahub-blue)](https://datahub.berkeley.edu/hub/user-redirect/git-pull?repo=https%3A%2F%2Fgithub.com%2Fdlab-berkeley%2FPython-Fundamentals&urlpath=tree%2FPython-Fundamentals%2F&branch=main) [![Binder](http://mybinder.org/badge.svg)](https://mybinder.org/v2/gh/dlab-berkeley/Python-Fundamentals/main?urlpath=tree) +[![Datahub](https://img.shields.io/badge/launch-datahub-blue)](https://dlab.datahub.berkeley.edu/hub/user-redirect/git-pull?repo=https%3A%2F%2Fgithub.com%2Fdlab-berkeley%2FPython-Fundamentals&urlpath=lab%2Ftree%2FPython-Fundamentals%2F&branch=main) +[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/dlab-berkeley/Python-Fundamentals/HEAD) +[![License: CC BY 4.0](https://img.shields.io/badge/License-CC_BY_4.0-lightgrey.svg)](https://creativecommons.org/licenses/by/4.0/) -This repository contains the materials for D-Lab’s Python Fundamentals workshop. No prior experience with Python is required. +This repository contains the materials for D-Lab’s Python Fundamentals workshop. +No prior experience with Python is required to attend this workshop. ## Workshop Goals -In this workshop, we provide an introduction to Python. We do so in four main parts: +This four-part, interactive workshop series is your complete introduction to +programming Python for people with little or no previous programming experience. +By the end of the series, you will be able to apply your knowledge of basic +principles of programming and data manipulation to a real-world social science +application. -* **Part 1**: Introduction to Python and Jupyter Notebooks, variables, data types, and functions. +Each of the parts is divided into a lecture-style coding walkthrough interrupted +by challenge problems, discussions of the solutions, and breaks. Instructors and +TAs are dedicated to engaging you in the classroom and answering questions in +plain language. + +* **Part 1**: Introduction to Python and Jupyter Notebooks, variables, data + types, and functions. * **Part 2**: Data structures, loops, conditionals, and creating functions. * **Part 3**: Libraries, File I/O, and scientific computing. * **Part 4**: Error handling, style, and an applied, in-depth project. ## Installation Instructions -Anaconda is a useful package management software that allows you to run Python and Jupyter notebooks very easily. Installing Anaconda is the easiest way to make sure you have all the necessary software to run the materials for this workshop. Complete the following steps: +Anaconda is a useful package management software that allows you to run Python +and Jupyter notebooks easily. Installing Anaconda is the easiest way to make +sure you have all the necessary software to run the materials for this workshop. +If you would like to run Python on your own computer, complete the following +steps prior to the workshop: -1. [Download and install Anaconda (Python 3.9 distribution)](https://www.anaconda.com/products/individual). Click "Download" and then click 64-bit "Graphical Installer" for your current operating system. +1. [Download and install Anaconda (Python 3.9 + distribution)](https://www.anaconda.com/products/individual). Click the + "Download" button. -2. Download the [Python-Fundamentals workshop materials](https://github.com/dlab-berkeley/Python-Fundamentals): +2. Download the Python Fundamentals [workshop + materials](https://github.com/dlab-berkeley/Python-Fundamentals): -* Click the green "Code" button in the top right of the repository information. -* Click "Download Zip". -* Extract this file to a folder on your computer where you can easily access it (we recommend Desktop). + - Click the green "Code" button in the top right of the repository + information. + - Click "Download Zip". + - Extract this file to a folder on your computer where you can easily + access it (we recommend Desktop). -3. Optional: if you're familiar with `git`, you can instead clone this repository by opening a terminal and entering `git clone git@github.com:dlab-berkeley/Python-Fundamentals.git`. +3. Optional: if you're familiar with `git`, you can instead clone this + repository by opening a terminal and entering the command `git clone + git@github.com:dlab-berkeley/Python-Fundamentals.git`. -## Run the code +## Is Python Not Working on Your Laptop? -Now that you have all the required software and materials, you need to run the code: +If you do not have Anaconda installed and the materials loaded on your workshop +by the time it starts, we *strongly* recommend using the D-Lab Datahub to +run the materials for these lessons. You can access the DataHub by clicking the +following button: -1. Open the Anaconda Navigator application. You should see the green snake logo appear on your screen. Note that this can take a few minutes to load up the first time. +[![Datahub](https://img.shields.io/badge/launch-datahub-blue)](https://dlab.datahub.berkeley.edu/hub/user-redirect/git-pull?repo=https%3A%2F%2Fgithub.com%2Fdlab-berkeley%2FPython-Fundamentals&urlpath=lab%2Ftree%2FPython-Fundamentals%2F&branch=main) -2. Click the "Launch" button under "Jupyter Notebooks" and navigate through your file system to the `Python-Fundamentals` folder you downloaded above. +The DataHub downloads this repository, along with any necessary packages, and +allows you to run the materials in a Jupyter notebook that is stored on UC +Berkeley's servers. No installation is necessary from your end - you only need +an internet browser and a CalNet ID to log in. By using the DataHub, you can +save your work and come back to it at any time. When you want to return to your +saved work, just go straight to [DataHub](https://datahub.berkeley.edu), sign +in, and you click on the `Python-Fundamentals` folder. -3. In the folder, open the `00_workshop_setup.ipynb` to begin. +If you don't have a Berkeley CalNet ID, you can still run these lessons in the +cloud, by clicking this button: -4. Press Shift + Enter (or Ctrl + Enter) to run a cell. +[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/dlab-berkeley/Python-Fundamentals/HEAD) -## Is Python not working on your laptop? +Binder operates similarly to the D-Lab DataHub, but on a different set of +servers. By using Binder, however, you cannot save your work. -If you do not have Anaconda installed and the materials loaded on your workshop by the time it starts, we *strongly* recommend using the UC Berkeley Datahub to run the materials for these lessons. You can access the DataHub by clicking this button: +## Run the Code -[![Datahub](https://img.shields.io/badge/launch-datahub-blue)](https://datahub.berkeley.edu/hub/user-redirect/git-pull?repo=https%3A%2F%2Fgithub.com%2Fdlab-berkeley%2FPython-Fundamentals&urlpath=tree%2FPython-Fundamentals%2F&branch=main) +Now that you have all the required software and materials, you need to run the +code. -The DataHub downloads this repository, along with any necessary packages, and allows you to run the materials in a Jupyter notebook that is stored on UC Berkeley's servers. No installation is necessary from your end - you only need an internet browser and a CalNet ID to log in. By using the DataHub, you can save your work and come back to it at any time. When you want to return to your saved work, just go straight to [DataHub](https://datahub.berkeley.edu), sign in, and you click on the `Python-Fundamentals` folder. +1. Open the Anaconda Navigator application. You should see the green snake logo + appear on your screen. Note that this can take a few minutes to load up the + first time. -If you don't have a Berkeley CalNet ID, you can still run these lessons in the cloud, by clicking this button: +2. Click the "Launch" button under "JupyterLab" and navigate through your file + system on the left hand pane to the `Python-Fundamentals` folder you + downloaded above. Note that, if you download the materials from GitHub, the + folder name may instead be `Python-Fundamentals-main`. -[![Binder](http://mybinder.org/badge.svg)](https://mybinder.org/v2/gh/dlab-berkeley/Python-Fundamentals/main?urlpath=tree) +3. Open `00_workshop_setup.ipynb` to begin. -By using this button, you cannot save your work unfortunately. +4. Press Shift + Enter (or Ctrl + Enter) to run a cell. -# About the UC Berkeley D-Lab +Note that all of the above steps can be run from the terminal, if you're +familiar with how to interact with Anaconda in that fashion. However, using +Anaconda Navigator is the easiest way to get started if this is your first time +working with Anaconda. + +## Additional Resources -D-Lab works with Berkeley faculty, research staff, and students to advance data-intensive social science and humanities research. Our goal at D-Lab is to provide practical training, staff support, resources, and space to enable you to use R for your own research applications. Our services cater to all skill levels and no programming, statistical, or computer science backgrounds are necessary. We offer these services in the form of workshops, one-to-one consulting, and working groups that cover a variety of research topics, digital tools, and programming languages. +Check out the following online resources to learn more about Python: -Visit the [D-Lab homepage](https://dlab.berkeley.edu/) to learn more about us. You can view our [calendar](https://dlab.berkeley.edu/events/calendar) for upcoming events, learn about how to utilize our [consulting](https://dlab.berkeley.edu/consulting) and [data](https://dlab.berkeley.edu/data) services, and check out upcoming [workshops](https://dlab.berkeley.edu/events/workshops). +* [A Byte of Python](https://python.swaroopch.com) +* [Software Carpentry](https://swcarpentry.github.io/) +* [W3Schools](https://www.w3schools.com/python/) + +# About the UC Berkeley D-Lab + +D-Lab works with Berkeley faculty, research staff, and students to advance +data-intensive social science and humanities research. Our goal at D-Lab is to +provide practical training, staff support, resources, and space to enable you to +use R for your own research applications. Our services cater to all skill levels +and no programming, statistical, or computer science backgrounds are necessary. +We offer these services in the form of workshops, one-to-one consulting, and +working groups that cover a variety of research topics, digital tools, and +programming languages. + +Visit the [D-Lab homepage](https://dlab.berkeley.edu/) to learn more about us. +You can view our [calendar](https://dlab.berkeley.edu/events/calendar) for +upcoming events, learn about how to utilize our +[consulting](https://dlab.berkeley.edu/consulting) and [data +services](https://dlab.berkeley.edu/data), and check out upcoming +[workshops](https://dlab.berkeley.edu/events/workshops). Subscribe to our +[newsletter](https://dlab.berkeley.edu/news/weekly-newsletter) to stay up to +date on D-Lab events, services, and opportunities. # Other D-Lab Python Workshops -Here are other Python workshops offered by the D-Lab: +D-Lab offers a variety of Python workshops, catered toward different levels of +expertise. -### Basic competency +## Introductory Workshops -* [Python Fundamentals](https://github.com/dlab-berkeley/python-fundamentals) -* [Introduction to Pandas](https://github.com/dlab-berkeley/introduction-to-pandas) -* [Geospatial Fundamentals in Python](https://github.com/dlab-berkeley/Geospatial-Fundamentals-in-Python) +- [Python Data Wrangling](https://github.com/dlab-berkeley/Python-Data-Wrangling) +- [Python Data Visualization](https://github.com/dlab-berkeley/Python-Data-Visualization) -### Intermediate/advanced competency +## Intermediate and Advanced Workshops -* [Computational Text Analysis in Python](https://github.com/dlab-berkeley/computational-text-analysis-spring-2019) -* [Introduction to Machine Learning in Python](https://github.com/dlab-berkeley/python-machine-learning) -* [Introduction to Artificial Neural Networks in Python](https://github.com/dlab-berkeley/ANN-Fundamentals) -* [Fairness and Bias in Machine Learning](https://github.com/dlab-berkeley/fairML) +- [Python Geospatial Fundamentals](https://github.com/dlab-berkeley/Geospatial-Data-and-Mapping-in-Python) +- [Python Web Scraping and APIs](https://github.com/dlab-berkeley/Python-Web-Scraping) +- [Python Machine Learning](https://github.com/dlab-berkeley/Python-Machine-Learning) +- [Python Text Analysis](https://github.com/dlab-berkeley/Python-Text-Analysis) +- [Python Deep Learning](https://github.com/dlab-berkeley/Python-Deep-Learning) # Contributors + * Emily Grabowski * Pratik Sachdeva * Christopher Hench pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy