diff --git a/README.md b/README.md index 41ef260..20408de 100644 --- a/README.md +++ b/README.md @@ -7,44 +7,64 @@ `-' ``` -## Python mini boot camp at [#NICAR20](https://www.ire.org/events-and-training/conferences/nicar-2020/) in New Orleans. +# Python mini bootcamp -In this two-day workshop, we'll use the Jupyter notebook to explore the Python programming language. At the end of the class, we'll give you all of the code from the exercises, along with several cheatsheets and tutorials, to take home with you, all from this code repository on Github. +In this two-day workshop, we'll learn the basics of the Python programming language and how to begin analyzing data in a Jupyter Notebook. What's a Notebook? It's an interactive coding environment that lets you blend words and code. -### Day 1 -#### [Introduction](https://ireapps.github.io/pycar/pycar_intro.html) +Confused? Of course. + +Bear with us. It will all make sense soon. + +> Instructors, check out the [Teacher's Guide](teachers_guide.md). + +## Day 1 + +### Intros * Who are you, what do you do, what do you want to learn? * What will we learn? * What can I do with it? -* The goal of the day is to start to learn how to think about solving problems. +* GOAL: Learn how to solve problems with code. + +### [The Basics](basics/README.md) +Key concepts of programming in Python: + +- Basic data types - strings, integers, lists +- Lists are your friend! +- etc + +> Bonus: a [discussion on debugging][] and handy [cheatsheet](debug/DebugginginPython.pdf) -#### [The Basics](https://github.com/ireapps/pycar/tree/master/basics) -We'll introduce some key concepts of programming and Python types like strings, integers, lists, slicing and loops. +[discussion on debugging]: https://docs.google.com/presentation/d/e/2PACX-1vTCwzQnH0Ps8xmqnxGBYayCyas8-53qJyo-yjIy5qy4P2xUOA-kiAOQCNTiCzRBVX7TxeBabx1pvpBQ/pub?start=false&loop=false&delayms=3000 -#### A [discussion on debugging](https://docs.google.com/presentation/d/e/2PACX-1vTCwzQnH0Ps8xmqnxGBYayCyas8-53qJyo-yjIy5qy4P2xUOA-kiAOQCNTiCzRBVX7TxeBabx1pvpBQ/pub?start=false&loop=false&delayms=3000) and [cheatsheet](https://github.com/ireapps/pycar/tree/master/debug/DebugginginPython.pdf) +## Day 2 +### [Project #1](project1/README.md) -### Day 2 -#### [Project #1](https://github.com/ireapps/pycar/tree/master/project1) As with many data analyses, it all starts with a CSV. After a white board exercise, we'll start with a file of pseudocode, and we'll walk through writing the program in Python code, running each line in the Jupyter interpreter. We'll hold your hand through each step of the process. -#### [Project #2](https://github.com/ireapps/pycar/tree/master/project2) +### [Project #2](/project2/README.md) + +> This project is out-of-date. We'll try to update it in the near future. + This section covers gathering data from the web in two common formats. + In the first part, we'll scrape structured data from an HTML page using a GET request and write the data to a CSV. In the second part, we'll request data from an API to get information programmatically to create a spreadsheet. Our data comes in a new format: JSON. We'll do some more with the white board to show how it's basically a combination of data structures we already know about: Lists and dictionaries (arrays and objects). -#### [Project #3](https://github.com/ireapps/pycar/tree/master/project3) -Now we get to the heart of data analysis with an introduction to the powerful `pandas` library. Building on the basic objects we've already learned, and on a little knowledge of SQL, we'll clean two related tables of data, join and filter them. +### [Project #3](project3/analyzing_data_with_pandas_notebook.ipynb) + +Now we get to the heart of data analysis with an introduction to the powerful [pandas](https://pandas.pydata.org/docs/index.html) library. Building on the basics we've already learned, and a little knowledge of [SQL](https://en.wikipedia.org/wiki/SQL), we'll clean two related tables of data, join and filter them. At the end of the day, we'll __[send you home with](takehome/README.md)__: -* A [lightning dash](https://github.com/ireapps/pycar/tree/master/takehome/PyCAR_basics_takehome_notebook_complete.ipynb) through basic variables, types and functions -* The [working, commented code](https://github.com/ireapps/pycar/tree/master/completed) for each project from our git repo +* A [lightning dash](takehome/PyCAR_basics_takehome_notebook_complete.ipynb) through basic variables, types and functions +* The [working, commented code](completed/) for each project from our git repo * A walkthrough for [setting up your machine at home with Python](https://github.com/thejqs/pycar/blob/master/takehome/Installing%20Python%20The%20IRE%20Way%E2%84%A2.pdf), version control and virtualenvs * Good libraries to explore with strong tutorials * A lifetime support guarantee [from us](CONTRIBUTORS.md) & [PythonJournos](https://groups.google.com/forum/#!forum/PythonJournos) -### Help! +## Help! + If you're working through this code at home and have trouble, please let us know. -The best option is to [file an issue report](https://github.com/ireapps/pycar/issues?q=is%3Aopen+is%3Aissue) of the bug so we can help you. -You can also reach out to any of us [on Twitter](https://github.com/ireapps/pycar/blob/master/CONTRIBUTORS.md) or ping [PythonJournos](https://groups.google.com/forum/#!forum/PythonJournos). + +The best way to reach us is by [submitting an Issue](https://github.com/ireapps/pycar/issues?q=is%3Aopen+is%3Aissue) on GitHub. \ No newline at end of file diff --git a/basics/README.md b/basics/README.md index cd0f7ca..e8d291d 100644 --- a/basics/README.md +++ b/basics/README.md @@ -1,11 +1,11 @@ -THE BASICS -========== +# THE BASICS -**9:30 - 10:45 a.m.** + +> Approx. 1 hour, 15 minutes What is a [number](https://docs.python.org/3/tutorial/introduction.html#numbers)? What is a [string](https://docs.python.org/3/tutorial/introduction.html#strings)? What is a [list](https://docs.python.org/3/tutorial/introduction.html#lists)? -Nevermind that, what's a [Python](https://docs.python.org/3.6/)? +Nevermind that, what's a [Python](https://docs.python.org/3/)? Before we get started with learning programming concepts, let's take a step back and get a high-level overview of what programming even is. @@ -13,17 +13,17 @@ Programming is not mystical, magical or special. Programming is more of a craft You already know the components of programming. You have been exercising the reasoning programming relies on for your entire life, probably without even realizing it. Programming is just a way to take the logic you already use on a daily basis and express it in a way a computer can understand and act upon. -Card games and games like tic-tac-toe are classic programming tests because they require you to encapsulate the way you reason about those games in a way a computer can understand. So we'll use a card game, solitaire, to talk about some basic programming concepts over in the `basics_notebook`. Head over there, and then come back here for some reference. +Card games and games like tic-tac-toe are classic programming tests because they require you to encapsulate the way you reason about those games in a way a computer can understand. So we'll use a card game, solitaire, to talk about some basic programming concepts over in the [basics_notebook.ipynb](basics_notebook.ipynb). Head over there, and then come back here for some reference. ## About Python Python is a programming language. It was created around 1991 by an individual named [Guido van Rossum](https://en.wikipedia.org/wiki/Guido_van_Rossum). -You may hear others call Python a [scripting language](https://en.wikipedia.org/wiki/Scripting_language). You may also hear it called an interpretative language. In essence, these are interchangeable terms. In Python you write programs that are interpreted line by line. These programs - or scripts - automate tasks that would otherwise be completed one by one. +You may hear others call Python a [scripting language](https://en.wikipedia.org/wiki/Scripting_language). You may also hear it called an ["interpreted"](https://en.wikipedia.org/wiki/Interpreter_(computing)) language. In essence, these are interchangeable terms. In Python you write programs that are interpreted line by line. These programs - or scripts - automate tasks that would otherwise be completed one by one. The Python interpreter can be accessed through the command line (terminal, shell, etc). On Unix-based (Mac OS) or Linux machines, which come with Python installed by default, you enter the Python interpreter by typing ```python``` followed by the return key. On a Windows machine, things are a bit more cumbersome. -One feature of Python that takes some getting used to is its use of indentation to organize blocks of code. One to remember this is to think of creating an outline. You have main bullet points and you might have an item indented beneath that relates to something above it. In essence, this is python. +One feature of Python that takes some getting used to is its use of indentation to organize blocks of code. One way to remember this is to think of creating an outline. You have main bullet points and you might have an item indented beneath that relates to something above it. In essence, this is Python. the python interpreter reads this line first and takes action and then reads this line and takes action @@ -34,211 +34,234 @@ Before we get started, this is meant to be an overview of Python and show you so > While you are studying programming, I'm studying how to play guitar. I practice it every day for at least two hours a day. I play scales, chords, and arpeggios for an hour and then learn music theory, ear training, songs, and anything else I can. Some days I study guitar and music for eight hours because I feel like it and it's fun. To me repetitive practice is natural and just how to learn something. I know that to get good at anything you have to practice every day, even if I suck that day (which is often) or it's difficult. Keep trying and eventually it'll be easier and fun. -Anyways, let's get started by looking at some key components of any programming language - variables, strings, numbers and comparisons. All of this is contained within the [official Python tutorial](https://docs.python.org/3.7/tutorial/introduction.html#) to the standard library. We'll consider Python lists as a container that we can fill and we'll work toward using a couple core libraries - ```urllib``` and ```csv``` - to download a CSV file and read the contents. +Anyways, let's get started by looking at some key components of any programming language - numbers, text, comparisons and variables. -**The files** +All of the following is contained within the [official Python tutorial](https://docs.python.org/3/tutorial/introduction.html#). -* ```basics.py``` and ```complete/basics_complete.py``` +We'll work on the below exercises in [basics_reference_notebook.ipynb](basics_reference_notebook.ipynb). - * Indentation +> Solutions to the exercises can be found in +[completed/basics_reference_completed.ipynb]([../completed/basics_reference_completed.ipynb]). - * As mentioned in the introduction, Python uses indentation to structure its code blocks instead of braces, brackets, or keywords. This comes into play later on in the session when we begin to write ```if``` statements, ```for``` loops and ```define``` functions. For example: +## Side note: Comments +Throughout the day you will see - and hear us refer to - something called comments. We're not referring to that wasteland of negativity that you find at the bottom of articles on news websites. But just the same, ideally these comments are meant to be constructive. - def my_first_function(input): - if input == None: - output = "I have nothing" - else: - output = "I have something" +* Comments are annotations; a method for programmers to offer notes, advice or justification for why the did something in a script. + +Python has a couple ways to comment code: + +One is to use the pound symbol, aka hashtag or [octothorp](https://en.wikipedia.org/wiki/Number_sign). Here's an example: - * Lines are indented by four spaces. +``` +# this part of the code is where I make the magic happen +``` - * Comments +Another method for multiline comments is to use a series of three quote marks or three apostrophes. - * Throughout the day you will see - and hear us refer to - something called comments. We're not referring to that wasteland of negativity that you find at the bottom of articles on news websites. But just the same, ideally these comments are meant to be constructive. +``` +""" +this is a multiline comment +so i can pack more information +about what i'm doing +""" +``` - * Comments are annotations; a method for programmers to offer notes, advice or justification for why the did something in a script. +## Variables - * Python has a couple ways to comment code +* A variable is a named container for a value. - * One is to use the pound symbol, aka hashtag or [octothorp](https://en.wikipedia.org/wiki/Number_sign). Here's an example +* A backbone of any programming language - # this part of the code is where I make the magic happen +* Variables have a scope - * Another method for multiline comments is to use a series of three quote marks or three apostrophes. +* Variables have a value - """ - this is a multiline comment - so i can pack more information - about what i'm doing - """ + * Can be None - * Variables + * Can be True or False - * A variable is a named container for a value + * Or it could be something else... a number or a string - * A backbone of any programming language +* When declaring the value of for a variable in Python the format is 'variable = value' - * Variables have a scope + * ```my_variable = "the value of my variable"``` - * Variables have a value +## Text - * Can be None +[Text](https://docs.python.org/3/tutorial/introduction.html#text) (or more formally in Python, "strings"). - * Can be True or False +* Generally, synonymous with characters. - * Or it could be something else... a number or a string +* You can use double quotes or single quotes to create strings - * When declaring the value of for a variable in Python the format is 'variable equals value' +* If using single quotes, apostrophes and single quotes within string must be escaped - * ```my_variable = "my value of the variable"``` +* Learning about strings - * [Numbers](https://docs.python.org/2/tutorial/introduction.html#numbers) + * double quotes vs. single quotes - * Whole numbers have a type and that type is integer + # double quotes + double_quotes_string = "We're going to learn Python at #NICAR16" + print double_quotes_string - * Fractions have a type and that type is float + # single quotes + single_quotes_string = 'We\'re going to learn Python at #NICAR16' + print single_quotes_string - * Learning about numbers + * get its type - * get the [type](https://docs.python.org/2/library/functions.html#type) + * get its length - * addition + * [lowercase](https://docs.python.org/3/library/stdtypes.html?highlight=strip#str.lower) - * subtraction + * [uppercase](https://docs.python.org/3/library/stdtypes.html?highlight=strip#str.upper) - * multiplication + * [titlecase](https://docs.python.org/3/library/stdtypes.html?highlight=strip#str.title) - * division + * [split](https://docs.python.org/3/library/stdtypes.html?highlight=strip#str.split) - * order of operations + * join - * used when we want to determine percent change right? + * [replace a character](https://docs.python.org/3/library/stdtypes.html?highlight=strip#str.replace) - ```(new - old) / old``` + * strip whitespace - * [Strings](https://docs.python.org/2/tutorial/introduction.html#strings) + * [all](https://docs.python.org/3/library/stdtypes.html?highlight=strip#str.strip) - * Generally, synonymous with characters. + * [leading whitespace](https://docs.python.org/3/library/stdtypes.html?highlight=strip#str.lstrip) - * You can use double quotes or single quotes to create strings + * [trailing whitespace](https://docs.python.org/3/library/stdtypes.html?highlight=strip#str.rstrip) - * If using single quotes, apostrophes and single quotes within string must be escaped +## Numbers + +[Numbers](https://docs.python.org/3/tutorial/introduction.html#numbers) - * Learning about strings +* Whole numbers have a type and that type is integer - * double quotes vs. single quotes +* Fractions have a type and that type is float - # double quotes - double_quotes_string = "We're going to learn Python at #NICAR16" - print double_quotes_string +* Learning about numbers - # single quotes - single_quotes_string = 'We\'re going to learn Python at #NICAR16' - print single_quotes_string + * get the [type](https://docs.python.org/3/library/functions.html#type) - * get its type + * addition - * get its length + * subtraction - * [lowercase](https://docs.python.org/2/library/stdtypes.html?highlight=strip#str.lower) + * multiplication - * [uppercase](https://docs.python.org/2/library/stdtypes.html?highlight=strip#str.upper) + * division - * [titlecase](https://docs.python.org/2/library/stdtypes.html?highlight=strip#str.title) + * order of operations - * [split](https://docs.python.org/2/library/stdtypes.html?highlight=strip#str.split) + * used when we want to determine percent change right? + ``` + (new - old) / old + ``` - * join +## Lists - * [replace a character](https://docs.python.org/2/library/stdtypes.html?highlight=strip#str.replace) +[Lists](https://docs.python.org/3/tutorial/introduction.html#lists) - * strip whitespace +* We learned that integers and strings are data types - * [all](https://docs.python.org/2/library/stdtypes.html?highlight=strip#str.strip) + * Python has specific types that allow you to group items. The list is one of these collections. - * [leading whitespace](https://docs.python.org/2/library/stdtypes.html?highlight=strip#str.lstrip) + * A list is sortable and a list has an index - * [trailing whitespace](https://docs.python.org/2/library/stdtypes.html?highlight=strip#str.rstrip) + * Index starts at 0 - * [Lists](https://docs.python.org/2/tutorial/introduction.html#lists) + * You can add and remove content - * We learned that integers and strings are data types + * You can add and remove items from specific indexes - * Python has specific types that allow you to group items. The list is one of these collections. + * Lists might contain items of different types, but usually the items all have the same type. - * A list is sortable and a list has an index + * append() allows you to add items to a list - * Index starts at 0 + * pop() returns the element you want to remove. Useful to remove and keep an item from a list - * You can add and remove content + * By default, pop without any arguments removes the last item - * You can add and remove items from specific indexes + * del deletes the item at the specified index - * Lists might contain items of different types, but usually the items all have the same type. +## Dicts - * append() allows you to add items to a list +TK - * pop() returns the element you want to remove. Useful to remove and keep an item from a list - * By default, pop without any arguments removes the last item +## Indentation - * del deletes the item at the specified index +As mentioned in the introduction, Python uses indentation to structure "blocks" of code instead of braces, brackets, or keywords. For example: - * Conditionals & Comparisons +```python + if user_input is None: + output = "I have nothing" + else: + output = "I have something" +``` - * Conditional statements +* Lines are indented by four spaces. - * "[A conditional statement](https://en.wikipedia.org/wiki/Conditional_(computer_programming)), conditional expressions and conditional constructs are features of a programming language which perform different computations or actions depending on whether a programmer-specified boolean condition evaluates to true or false." - * [for](https://docs.python.org/2/tutorial/controlflow.html#for-statements) +## Conditionals & Comparisons - * The ```for``` statement iterates through a list or a string in the order they appear. +### Conditional statements - my_list = [1, 2, 3, 4, 5, 6] - for x in my_list: - print x +* "[A conditional statement](https://en.wikipedia.org/wiki/Conditional_(computer_programming)), conditional expressions and conditional constructs are features of a programming language which perform different computations or actions depending on whether a programmer-specified boolean condition evaluates to true or false." - * [if/elif/else](https://docs.python.org/2/tutorial/controlflow.html#if-statements) + * [for](https://docs.python.org/3/tutorial/controlflow.html#for-statements) - * The ```for``` statement iterates through a list or a string in the order they appear. + * The ```for``` statement iterates through a list or a string in the order they appear. + ```python + my_list = [1, 2, 3, 4, 5, 6] + for x in my_list: + print x + ``` + + * [if / elif / else](https://docs.python.org/3/tutorial/controlflow.html#if-statements) + + * The `for` statement iterates through a list or a string in the order they appear. + + value = 4 + if 4 == value: + print "it's the same" + else: + print "it's not the same" - value = 4 - if 4 == value: - print "it's the same" - else: - print "it's not the same" +### Comparisons - * [Comparisons](https://docs.python.org/2/library/stdtypes.html#comparisons) +[Comparisons (python docs)](https://docs.python.org/3/library/stdtypes.html#comparisons) - * equals (==) +* equals (`==`) - * are two values the same? + * are two values the same? - * not equals (!=) +* not equals (`!=`) - * are two values different? + * are two values different? - * greater than (>) +* greater than (`>`) - * is value larger than the other? + * is value larger than the other? - * greater than equal to (>=) +* greater than equal to (`>=`) - * is value larger or equal to the other? + * is value larger or equal to the other? - * less than (<) +* less than (`<`) - * is value smaller than the other? + * is value smaller than the other? - * less than equal to (<=) +* less than equal to (`<=`) - * is value smaller or equal to the other? + * is value smaller or equal to the other? - * is +* `is` - * Are two items the exact same thing? + * Are two items the exact same thing? - * is not +* `is not` - * Are two items not the exact same thing? + * Are two items not the exact same thing? diff --git a/basics/basics_notebook.ipynb b/basics/basics_notebook.ipynb index e1f450b..d83cdf9 100644 --- a/basics/basics_notebook.ipynb +++ b/basics/basics_notebook.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Python Basics at PyCAR2020" + "# Python Basics" ] }, { @@ -26,7 +26,7 @@ "\n", "(Most of us ask questions we've asked before daily — we just ask them of Google.)\n", "\n", - "Now for some code. Let's say you want to search 130,000 lines of text for certain tems -- which are most common, how frequently do they occur, how often are they used in a way that's concentrated, which might indicate places you want to look more closely.\n", + "Now for some code. Let's say you want to search 130,000 lines of text for certain terms -- which are most common, how frequently do they occur, how often are they used in a way that's concentrated, which might indicate places you want to look more closely.\n", "\n", "No person wants to do that by hand. And people are bad at precisely that kind of work. But it's perfect for a computer.\n", "\n", @@ -97,7 +97,7 @@ "source": [ "So any time we want to check to see how many times we've seen our `search_term` or check where our `file_location` is, we can use these variables instead of typing out the card value!\n", "\n", - "If you forget what one of the variables is set to, you can print your string. (The ```print()``` command was optional in Python 2.x, but is now required in Python 3.x.) Let's also make a comment to remind us of what this variable does." + "If you forget what one of the variables is set to, you can `print` your string. Let's also make a comment to remind us of what this variable does." ] }, { @@ -375,18 +375,25 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "As you’ve just seen, programming can be pretty tedious when you’re trying to break tasks down. So now that you’ve gotten a little bit of a taste for what writing a program is like, let’s dive into some of [the nitty-gritty basics](basics_reference_completed.ipynb), like how you strip whitespace from a string and what happens when you mix a float and an integer.\n", + "As you’ve just seen, programming can be pretty tedious when you’re trying to break tasks down. So now that you’ve gotten a little bit of a taste for what writing a program is like, let’s dive into some of [the nitty-gritty basics](../completed/basics_reference_completed.ipynb), like how you strip whitespace from a string and what happens when you mix a float and an integer.\n", "\n", "That sounds like a lot of fun. It must. It does. We promise.\n", "\n", "Onward." ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -400,9 +407,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.8" + "version": "3.11.6" } }, "nbformat": 4, - "nbformat_minor": 1 + "nbformat_minor": 4 } diff --git a/basics/basics_reference_notebook.ipynb b/basics/basics_reference_notebook.ipynb index 88b2b7b..5e14469 100644 --- a/basics/basics_reference_notebook.ipynb +++ b/basics/basics_reference_notebook.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Python Basics at PyCAR2020" + "# Python Basics" ] }, { @@ -32,7 +32,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Print your string. The ```print()``` command was optional in Python 2.x, but is now required in Python 3.x." + "Print your string" ] }, { @@ -258,7 +258,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Integers" + "## Numbers" ] }, { @@ -791,22 +791,13 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "This barely skims the surface of what you can do in Python, but hopefully this overview will make you comfortable enough to get started.\n", - "\n", - "Now, exit the program." + "This barely skims the surface of what you can do in Python, but hopefully this overview will make you comfortable enough to get started." ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -820,9 +811,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.8" + "version": "3.11.6" } }, "nbformat": 4, - "nbformat_minor": 1 + "nbformat_minor": 4 } diff --git a/completed/basics_complete_notebook.ipynb b/completed/basics_complete_notebook.ipynb index 5a7d3a3..09f8e1b 100644 --- a/completed/basics_complete_notebook.ipynb +++ b/completed/basics_complete_notebook.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Python Basics at PyCAR2020" + "# Python Basics" ] }, { @@ -26,7 +26,7 @@ "\n", "(Most of us ask questions we've asked before daily — we just ask them of Google.)\n", "\n", - "Now for some code. Let's say you want to search 130,000 lines of text for certain tems -- which are most common, how frequently do they occur, how often are they used in a way that's concentrated, which might indicate places you want to look more closely.\n", + "Now for some code. Let's say you want to search 130,000 lines of text for certain terms -- which are most common, how frequently do they occur, how often are they used in a way that's concentrated, which might indicate places you want to look more closely.\n", "\n", "No person wants to do that by hand. And people are bad at precisely that kind of work. But it's perfect for a computer.\n", "\n", @@ -52,7 +52,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -69,7 +69,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -86,7 +86,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -100,12 +100,12 @@ "source": [ "So any time we want to check to see how many times we've seen our `search_term` or check where our `file_location` is, we can use these variables instead of typing out the card value!\n", "\n", - "If you forget what one of the variables is set to, you can print it out. (The ```print()``` command was optional in Python 2.x, but is now required in Python 3.x.) Let's also make a comment to remind us of what this variable does." + "If you forget what one of the variables is set to, you can `print` it out. Let's also make a comment to remind us of what this variable does." ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -122,7 +122,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -132,7 +132,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -151,7 +151,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -168,7 +168,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ @@ -201,7 +201,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ @@ -217,7 +217,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ @@ -237,9 +237,17 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "achilles was in The Iliad 418 times\n" + ] + } + ], "source": [ "# we can do it by adding the strings to one another like this:\n", "print(search_term + ' was in The Iliad ' + str(term_count) + ' times')" @@ -247,9 +255,17 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "achilles was in The Iliad 418 times\n" + ] + } + ], "source": [ "# or we can use what Python calls `f-strings`, which allow us to drop variables directly into a string;\n", "# doing it this way means we don't have to keep track as much of wayward spaces or\n", @@ -266,9 +282,18 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "It was on the same line multiple times 5 times\n", + "it was on lines [11674, 13351, 16400, 20182, 20640] multiple times\n" + ] + } + ], "source": [ "print(f'It was on the same line multiple times {multi_term_line} {times}')\n", "print(f'it was on lines {line_numbers_list} multiple times')" @@ -290,7 +315,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, "outputs": [], "source": [ @@ -307,7 +332,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, "outputs": [], "source": [ @@ -323,7 +348,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": {}, "outputs": [], "source": [ @@ -340,7 +365,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": {}, "outputs": [], "source": [ @@ -357,7 +382,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "metadata": {}, "outputs": [], "source": [ @@ -374,9 +399,22 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "103\n", + "37\n", + "279\n", + "28\n", + "1\n", + "215\n" + ] + } + ], "source": [ "print(most_common_words[\"homer\"])\n", "print(most_common_words['paris'])\n", @@ -388,7 +426,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": {}, "outputs": [], "source": [ @@ -402,9 +440,19 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The most common word in The Iliad is: the\n", + "It is in The Iliad 15447 times\n", + "Wow! How cool is that?\n" + ] + } + ], "source": [ "print(f'The most common word in The Iliad is: {most_common_word}')\n", "print(f'It is in The Iliad {highest_count} times')\n", @@ -415,7 +463,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "As you’ve just seen, programming can be pretty tedious when you’re trying to break tasks down. So now that you’ve gotten a little bit of a taste for what writing a program is like, let’s dive into some of [the nitty-gritty basics](basics_reference_completed.ipynb), like how you strip whitespace from a string and what happens when you mix a float and an integer.\n", + "As you’ve just seen, programming can be pretty tedious when you’re trying to break tasks down. So now that you’ve gotten a little bit of a taste for what writing a program is like, let’s dive into some of [the nitty-gritty basics](../completed/basics_reference_completed.ipynb), like how you strip whitespace from a string and what happens when you mix a float and an integer.\n", "\n", "That sounds like a lot of fun. It must. It does. We promise.\n", "\n", @@ -433,7 +481,7 @@ "metadata": { "anaconda-cloud": {}, "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -447,9 +495,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.8" + "version": "3.11.6" } }, "nbformat": 4, - "nbformat_minor": 1 + "nbformat_minor": 4 } diff --git a/completed/basics_reference_completed.ipynb b/completed/basics_reference_completed.ipynb index f65dd0b..3d3311f 100644 --- a/completed/basics_reference_completed.ipynb +++ b/completed/basics_reference_completed.ipynb @@ -4,7 +4,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Python Basics at PyCAR2020" + "# Python Basics" ] }, { @@ -24,19 +24,17 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ - "my_string = \"We're going to learn Python at #nicar20\"" + "my_string = \"We're going to learn Python at #nicar24\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Print your string. The ```print()``` command was optional in Python 2.x, but is now required in Python 3.x." + "Print your string" ] }, { @@ -295,7 +293,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## integers" + "## Numbers" ] }, { @@ -308,9 +306,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "my_integer = 25" @@ -490,9 +486,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "a_list = [1, 2, 3]" @@ -508,9 +502,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "my_list = [\"We're going to learn Python at #NICAR16\", 10, 15, 20]" @@ -574,9 +566,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "my_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]" @@ -739,9 +729,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "mydict = {}" @@ -832,9 +820,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "x = 5\n", @@ -939,27 +925,14 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "This barely skims the surface of what you can do in Python, but hopefully this overview will make you comfortable enough to get started.\n", - "\n", - "Now, exit the program." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": true - }, - "outputs": [], - "source": [ - "exit()" + "This barely skims the surface of what you can do in Python, but hopefully this overview will make you comfortable enough to get started." ] } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -973,9 +946,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.8" + "version": "3.11.6" } }, "nbformat": 4, - "nbformat_minor": 1 + "nbformat_minor": 4 } diff --git a/static/img/codespace_bootstrap.png b/static/img/codespace_bootstrap.png new file mode 100644 index 0000000..7354aa9 Binary files /dev/null and b/static/img/codespace_bootstrap.png differ diff --git a/teachers_guide.md b/teachers_guide.md new file mode 100644 index 0000000..7ab2193 --- /dev/null +++ b/teachers_guide.md @@ -0,0 +1,70 @@ +# Teacher's Guide + +First off, a hearty thanks if you plan to help teach this course at NICAR! We appreciate you paying it forward :) + +Below is a rough overview (current as of NICAR24) to help onboard folks as teachers with (hopefully) as little friction as possible. + +Generally, each lesson plan includes the following elements: + +- `/README.md` - outline of the lesson plan, with important points to hit +- `/` - notebook with exercises (but no solutions) intended for students to work with during class +- `completed/` - a completed notebook containing solutions for the corresponding `/`. Instructors can print this or use a second screen to guide the lesson. + +Below are additional details on each lesson plan. + +## The Codespaces Two-Step + +As of NICAR24, we're using [GitHub Codespaces](https://github.com/features/codespaces) to work in Jupyter Notebooks. The goal is to minimize installation headaches by providing a preconfigured, cloud-based environment. + +At the start of class, instructors should: + +- Direct students to log into their GitHub accounts +- Go to the class repo on GH +- Click the big green `Code` button +- Select the Codespaces tab +- Click the big green `Create codespace...` button. + +Here's a screenshot: + +![codespace bootstrap](static/img/codespace_bootstrap.png) + +It usually takes a few minutes to initially spin up due to customizations we've made to the environment. + +Might be helpful during this time to provide a brief overview of Codespaces, noting in particular that it uses VS Code so everything they're about to learn in the cloud transfers easily to working on their own machines beyond class. + +Also worth mentioning: + +- It's a freemium model and generally they shouldn't incur any charges (or have to put down a credit card) with reasonable usage levels. +- The coding environment is saved for a day (or two?), so students can pick up their work on Day 2 right where they left off. + +### Codespace customizations + +The Codespaces environment for this repo has been customized to use a recent version of Python and to automatically install various libraries used in the lessons (e.g. `pandas`), along with important VS Code extensions for Python and Jupyter. + +To update the Python version and add dependencies or VS Code extensions, check out the Codespace configuration and Dockerfile in the `.devcontainer` folder. Also relevant is the GitHub action that controls the build process: `.github//workflows/docker-image.yaml`. + +If you discover you're missing a library in the middle of class, as a simple fallback you can open the terminal shell and just `pip install` libraries as needed. + +Also, note that whenever you create/open a Jupyter Notebook for the first time in Codespaces, you'll need to select a Python kernel. Codespaces/VS Code typically prompts you to select the kernel on the first attempt to run a notebook cell with an `import` statement. It's an arcane bit of workflow for students new to programming, but it should only take a few moments to walk them through the process. + +## Basics + +Provides an overview of basic Python data types and syntax. Here's the order of operations: + +- `basics/README.md` - Big picture on coding and outline of Python language basics that will be covered in the first notebook. +- `basics/basics_reference_notebook.ipynb` - exercise notebook that students should open and work in during the lesson +- `completed/basics_reference_completed.ipynb` - teacher's guide/solutions for `basics/basics_reference_notebook.ipynb` + +TK - `basics/basics_notebook.ipynb` and corresponding completed notebook + +## Project 1 + +TK + +## Project 2 + +> This is obsolete as of NICAR 2024. Skip straight to Project 3 + +## Project 3 + +TK \ No newline at end of file