Skip to content

Commit

Permalink
Start tidying up the litebook
Browse files Browse the repository at this point in the history
  • Loading branch information
palewire committed Sep 16, 2022
1 parent b44aefa commit 6c277f1
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 24 deletions.
Binary file added docs/src/_static/img/labpreview.webp
Binary file not shown.
Binary file added docs/src/_static/img/pandas-pypi.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
114 changes: 90 additions & 24 deletions jupyterlite/fast-python-notebook/notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@
"tags": []
},
"source": [
"# (_Faster_) First Python Notebook\n",
"# ~~First~~ Fast Python Notebook\n",
"\n",
"An accelerated guide to analyzing data with Python and the Jupyter notebook\n",
"<div style=\"max-width: 640px\">\n",
"\n",
"An accelerated guide to analyzing data with the [Python](https://www.python.org/) programming language and a [Jupyter](https://jupyter.org/) notebook\n",
"\n",
"</div>\n",
" \n",
"By [Ben Welsh](https://palewi.re/who-is-ben-welsh/)"
]
},
Expand All @@ -19,7 +23,13 @@
"id": "78f5946d-3e22-4eff-85a8-f066109c41b0",
"metadata": {},
"source": [
"First developed in 2016, \"First Python Notebook\" guides students through a data-driven investigation of money in California politics. It is most commonly taught as a six-hour in-person class. This document, the _FASTER EDITION_, is an abbreviated spin off intended to be taught online in two hours or less. The full course can be found at [palewi.re/docs/first-python-notebook/](https://palewi.re/docs/first-python-notebook/)."
"<div style=\"max-width: 640px\">\n",
"\n",
"First developed in 2016, [\"First Python Notebook\"](https://palewi.re/docs/first-python-notebook/) is a tutorial that guides students through a data-driven investigation of money in California politics. It is most commonly taught as a six-hour, in-person class. This document is an abbreviated spinoff intended to be taught online in two to three hours.\n",
"\n",
"You will learn just enough of the Python computer programming language to work with the [pandas](https://pandas.pydata.org/) library, a popular open-source tool for analyzing data. The course will teach you how to read, filter, join, group, aggregate and rank structured data by recreating a helicopter accident analysis [published by the Los Angeles Times](https://github.com/datadesk/helicopter-accident-analysis).\n",
" \n",
"</div>"
]
},
{
Expand All @@ -29,28 +39,34 @@
"tags": []
},
"source": [
"## Jupyter notebooks"
"## What is a Jupyter notebook?"
]
},
{
"cell_type": "markdown",
"id": "d6129fc8-71b6-40ed-a8c5-e18f50a5d981",
"metadata": {},
"source": [
"A [Jupyter](https://jupyter.org/) notebook is a browser-based interface where you can write, run, remix and republish code. It is free software that anyone can install and run like any other open-source library.\n",
"![jupyter](https://jupyter.org/assets/homepage/labpreview.webp)\n",
"\n",
"<div style=\"max-width: 640px\">\n",
"\n",
"A [Jupyter](https://jupyter.org/) notebook is a browser-based interface where you can write, run, remix and republish code. It is free software that anyone can install and run.\n",
"\n",
"[Scientists](https://nbviewer.jupyter.org/github/robertodealmeida/notebooks/blob/master/earth_day_data_challenge/Analyzing%20whale%20tracks.ipynb), [scholars](https://nbviewer.jupyter.org/github/nealcaren/workshop_2014/blob/master/notebooks/5_Times_API.ipynb), [investors](https://github.com/rsvp/fecon235/blob/master/nb/fred-debt-pop.ipynb) and corporations use Jupyter to create and share their research. It is also used by journalists to develop stories and show their work. Examples include:\n",
"[Scientists](https://nbviewer.jupyter.org/github/robertodealmeida/notebooks/blob/master/earth_day_data_challenge/Analyzing%20whale%20tracks.ipynb), [scholars](https://nbviewer.jupyter.org/github/nealcaren/workshop_2014/blob/master/notebooks/5_Times_API.ipynb), [investors](https://github.com/rsvp/fecon235/blob/master/nb/fred-debt-pop.ipynb) and [corporations](https://netflixtechblog.com/notebook-innovation-591ee3221233) use Jupyter to create and share their research. It is also used by journalists to develop stories and show their work. Examples include:\n",
"\n",
"* [“The Tennis Racket”](https://github.com/BuzzFeedNews/2016-01-tennis-betting-analysis/blob/master/notebooks/tennis-analysis.ipynb) by BuzzFeed and the BBC\n",
"* [“Machine bias”](https://github.com/propublica/compas-analysis/blob/master/Compas%20Analysis.ipynb) by ProPublica\n",
"* [“As Opioid Crisis Ramped Up, Pills Flowed Into Vermont by the Millions”](https://github.com/asuozzo/arcos-opioid-analysis-vt) by Seven Days\n",
"* [More than 35 different notebooks](https://github.com/datadesk/notebooks) published by the Los Angeles Times\n",
"\n",
"There are numerous ways to install and configure Jupyter notebooks. If don't have one running already, consult [the guide in the full edition of \"First Python Notebook.'](https://palewi.re/docs/first-python-notebook/jupyter_desktop.html)\n",
"There are numerous ways to install and configure Jupyter notebooks. This class is taught using [JupyterLite](https://jupyterlite.readthedocs.io/) a lightweight distribution that runs entirely in your web browser. For instructions on how to install a more powerful version on your computer consult [the full edition of \"First Python Notebook.'](https://palewi.re/docs/first-python-notebook/jupyter_desktop.html)\n",
"\n",
"Once you have this notebook set up and running, you're ready to write Python in a code cell. Do not stress. There is nothing too fancy about it. You can start by just doing a little simple math.\n",
"Once you have this notebook up and running, you're ready to write Python in a code cell. Do not stress. There is nothing too fancy about it. You can start by just doing a little simple math.\n",
"\n",
"Select the box below, then hit the play button in the toolbar above the notebook or hit `SHIFT+ENTER` on your keyboard."
"Select the box below, then hit the play button in the toolbar above the notebook or hit `SHIFT+ENTER` on your keyboard.\n",
" \n",
"</div>"
]
},
{
Expand All @@ -76,25 +92,43 @@
},
{
"cell_type": "markdown",
"id": "aed7d280-9237-4c24-9f43-ed5b4464a8d8",
"id": "8d878e7a-8c26-4ea9-992b-cc306e4c8e1c",
"metadata": {},
"source": [
"<div style=\"max-width:630px\">\n",
"\n",
"There. You have just run your first Python code. You have entered two integers and added them together using the plus sign operator.\n",
"\n",
"Not so bad, right?"
"Not so bad, right? Now try writing in your own math problem in the next cell. Maybe `2+3` or `2+200`. Whatever strikes your fancy. After you've typed it in, hit the play button or `SHIFT+ENTER`.\n",
"\n",
"</div>"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "561fbe22-81a9-49ba-8e92-d466063f9ba6",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "2c6b8af9-aad3-4ab6-b688-c0d755991845",
"id": "aed7d280-9237-4c24-9f43-ed5b4464a8d8",
"metadata": {},
"source": [
"This to-and-fro of writing Python code in a cell and then running it with the play button is the rhythm of working in a notebook. If you get an error after you run a cell, look carefully at your code and see that it exactly matches what’s been written in the example."
"<div style=\"max-width: 640px;\">\n",
"\n",
"This to-and-fro of writing Python code in a cell and then running it is the rhythm of working in a notebook. If you get an error after you run a cell, look carefully at your code and see that it exactly matches what’s been written in the example.\n",
" \n",
"Here's an example of a error that I've added intentionally:\n",
" \n",
"</div>"
]
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 4,
"id": "6aa5381f-2daf-40a7-bfa1-9e0c62ac3a5c",
"metadata": {},
"outputs": [
Expand All @@ -103,7 +137,7 @@
"evalue": "invalid syntax (4150814810.py, line 1)",
"output_type": "error",
"traceback": [
"\u001b[0;36m File \u001b[0;32m\"/tmp/ipykernel_1225627/4150814810.py\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m 2+2+\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n"
"\u001b[0;36m Input \u001b[0;32mIn [4]\u001b[0;36m\u001b[0m\n\u001b[0;31m 2+2+\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n"
]
}
],
Expand All @@ -116,7 +150,11 @@
"id": "8d75df45-7b74-4c47-8683-0e8fb69e7898",
"metadata": {},
"source": [
"Don’t worry. Code crashes are a normal part of life for computer programmers. They’re usually caused by small typos that can be quickly corrected."
"<div style=\"max-width: 640px;\">\n",
"\n",
"Don’t worry. Code crashes are a normal part of life for computer programmers. They’re usually caused by small typos that can be quickly corrected.\n",
" \n",
"</div>"
]
},
{
Expand Down Expand Up @@ -145,11 +183,15 @@
"id": "2c48af4c-0230-4624-accd-81589e0293cc",
"metadata": {},
"source": [
"<div style=\"max-width: 640px;\">\n",
"\n",
"Over time you will gradually stack cells to organize an analysis that runs from top to bottom. The cells can contain variables, functions and other Python tools.\n",
"\n",
"> Note: If you’ve never written Python before, we recommend [\"An Informal Introduction to Python\"](https://docs.python.org/3/tutorial/introduction.html) and subsequent sections of python.org’s tutorial.\n",
"> Note: If you’ve never written code before, we recommend [\"An Informal Introduction to Python\"](https://docs.python.org/3/tutorial/introduction.html) and subsequent sections of python.org’s tutorial.\n",
"\n",
"A simple example would be storing your number in a variable in one cell:"
"A simple example would be storing your number in a variable in one cell:\n",
" \n",
"</div>"
]
},
{
Expand Down Expand Up @@ -196,12 +238,12 @@
"id": "7b403eaa-d83e-4819-871f-2e8606936f71",
"metadata": {},
"source": [
"Change the number value to 3 and run both cells again and it should output 6."
"Change the `number` value to 3 and run both cells again. Instead of 5, it should now output 6."
]
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 5,
"id": "b33b8643-b444-4253-b38a-4be2732ddbdb",
"metadata": {},
"outputs": [],
Expand All @@ -211,7 +253,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 6,
"id": "00f55723-8907-4797-ba39-854a77c6a28c",
"metadata": {},
"outputs": [
Expand All @@ -221,7 +263,7 @@
"6"
]
},
"execution_count": 7,
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -230,6 +272,22 @@
"number + 3"
]
},
{
"cell_type": "markdown",
"id": "c223912c-1c04-4c3d-a2b3-4904ee39039b",
"metadata": {},
"source": [
"Now try defining your own numeric variable and doing some math with it. You can name it whatever you want. Want to try some other math operations? The `-` sign does subtraction. Multipication is `*`. Division is `/`."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2c19513b-1a01-4287-8e29-4362c4fc590f",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "997aa7c1-aa6c-4f5b-a8de-802990e87122",
Expand All @@ -245,9 +303,17 @@
"tags": []
},
"source": [
"## Pandas"
"## What is Pandas?"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0fb66d2d-cd31-4e26-9531-63c05c8b3dd3",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "6a769ba4-a9a9-4c26-bbfd-a14ea202b81a",
Expand Down Expand Up @@ -3745,7 +3811,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.12"
"version": "3.9.9"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 6c277f1

Please sign in to comment.