Created
September 14, 2020 17:44
-
-
Save edraizen/b62f29db0b8a6dad30382436f0cd6b6b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"slideshow": { | |
"slide_type": "slide" | |
} | |
}, | |
"source": [ | |
"# <center> An introduction to Jupyter notebooks </center>\n", | |
"## <center> UVA BME4550 <br> September 14th 2020 </center>\n", | |
"#### <center> Modified from [ECS Data Science Hack Week 2018](https://ecshackweek.github.io/tutorial/getting-started-with-jupyter/)</center>" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"slideshow": { | |
"slide_type": "slide" | |
} | |
}, | |
"source": [ | |
"## What is Jupyter?\n", | |
"\n", | |
"### It's a browser based application allowing you to run \"notebooks\" in your browser.\n", | |
"### These notebooks can contain code" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2017-10-04T13:00:23.817284Z", | |
"start_time": "2017-10-04T09:00:23.797270-04:00" | |
}, | |
"slideshow": { | |
"slide_type": "fragment" | |
} | |
}, | |
"outputs": [], | |
"source": [ | |
"a = 42\n", | |
"\n", | |
"print(a)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import datetime\n", | |
"\n", | |
"michiganStrikeStart = datetime.date(2020, 9, 8)\n", | |
"now = datetime.datetime.now().date()\n", | |
"\n", | |
"print('University of Michigan Graduate Students have been striking for {} days!'.format((now-michiganStrikeStart).days))" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## You can run bash commands (Must use `!`)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"!echo \"This is a notebook\"" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## You can add images:" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"<img src=\"https://pbs.twimg.com/profile_images/1299120224751562752/nGHJbhC8_400x400.jpg\" width=200 />\n", | |
"<img src=\"https://pbs.twimg.com/media/Eg_Zqh7XcAAaEiq?format=jpg&name=large\" width=300 />" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## You can add Markdown Syntax:" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"slideshow": { | |
"slide_type": "fragment" | |
} | |
}, | |
"source": [ | |
"### Lists\n", | |
"- a\n", | |
"- b \n", | |
"\n", | |
"### Equations\n", | |
"$$\n", | |
"\\frac{\\partial (\\epsilon c)}{\\partial t} = \\frac{\\partial}{\\partial x}\\left( \\epsilon D_{eff}\\frac{\\partial c}{\\partial x} \\right) + a (1-t_+^0) j_n\n", | |
"$$\n", | |
"\n", | |
"### Tables\n", | |
"\n", | |
"| Name | | Column |\n", | |
"|:---:|:---:|:---:|\n", | |
"||This is a fun table||\n", | |
"|To Do| Fill in the rest| |" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"slideshow": { | |
"slide_type": "slide" | |
} | |
}, | |
"source": [ | |
"# Easy development of code in bite size chunks" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"slideshow": { | |
"slide_type": "subslide" | |
} | |
}, | |
"source": [ | |
"### Data intensive step" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2017-10-04T03:06:05.388792Z", | |
"start_time": "2017-10-03T23:06:05.322745-04:00" | |
}, | |
"slideshow": { | |
"slide_type": "fragment" | |
} | |
}, | |
"outputs": [], | |
"source": [ | |
"# import the pandas package\n", | |
"import pandas as pd\n", | |
"\n", | |
"# read in the data from our file\n", | |
"file_location = 'https://raw.githubusercontent.com/mdmurbach/ECS-Hack-Day-2017/master/time-data(833).txt?raw=true'\n", | |
"data = pd.read_csv(file_location)\n", | |
"\n", | |
"# assign names to each of the columns for easy reference\n", | |
"data.columns = ['time(s)', 'current(A)', 'potential(V)', 'frequency(Hz)', 'amplitude(A)']\n", | |
"\n", | |
"# print out the first 5 rows of our data\n", | |
"data.head()" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2017-10-01T14:30:01.275550Z", | |
"start_time": "2017-10-01T10:30:01.267548-04:00" | |
}, | |
"slideshow": { | |
"slide_type": "subslide" | |
} | |
}, | |
"source": [ | |
"### Followed by a visualization or exploratory data analysis" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2017-10-04T03:06:08.103465Z", | |
"start_time": "2017-10-03T23:06:07.741502-04:00" | |
}, | |
"slideshow": { | |
"slide_type": "fragment" | |
} | |
}, | |
"outputs": [], | |
"source": [ | |
"#Make sure matplotlib plots in the borwser\n", | |
"%matplotlib inline \n", | |
"\n", | |
"# import the matplotlib package\n", | |
"import matplotlib.pyplot as plt\n", | |
"\n", | |
"# plot the current and voltage vs time\n", | |
"plt.plot(data['time(s)'], data['current(A)'])\n", | |
"plt.plot(data['time(s)'], data['potential(V)'])\n", | |
"\n", | |
"plt.show()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2017-10-04T03:06:08.926572Z", | |
"start_time": "2017-10-03T23:06:08.916565-04:00" | |
}, | |
"slideshow": { | |
"slide_type": "fragment" | |
} | |
}, | |
"outputs": [], | |
"source": [ | |
"mean_current = data[\"current(A)\"].mean()\n", | |
"mean_potential = data[\"potential(V)\"].mean()\n", | |
"\n", | |
"print('Mean current = {0} A; Mean potential = {1} V'.format(mean_current, mean_potential))" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"slideshow": { | |
"slide_type": "slide" | |
} | |
}, | |
"source": [ | |
"# Tips and tricks (keyboard shortcuts and %magic)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"slideshow": { | |
"slide_type": "fragment" | |
} | |
}, | |
"source": [ | |
"# Keyboard shortcuts\n", | |
"### Command mode vs. Edit mode\n", | |
"\n", | |
"Toggle with `esc` and `enter` keys\n", | |
"\n", | |
"### Useful command mode shortcuts\n", | |
"|Command|Action|\n", | |
"|:-----:|:----:|\n", | |
"|a|Create new cell above|\n", | |
"|b|Create new cell below|\n", | |
"|d d|Delete current cell|\n", | |
"|z| Undo delete cell|\n", | |
"|m|Change cell to markdown|\n", | |
"|y|Change cell to code|\n", | |
"|h| Bring up the list of shortcuts|\n", | |
"\n", | |
"### Useful editing shortcuts\n", | |
"\n", | |
"|Command|Action|\n", | |
"|:-----:|:----:|\n", | |
"|Ctrl-a|Select all|\n", | |
"|Ctrl-c|Copy|\n", | |
"|Ctrl-v|Paste|\n", | |
"|Ctrl-s|Save|\n", | |
"|Tab| Autocomplete |\n", | |
"|Shift-tab| Tooltips|" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# %magics!\n", | |
"\n", | |
"Commands that add additional (usually more advanced) features to the notebook\n", | |
"\n", | |
"|Magic|Action|\n", | |
"|:-----:|:----:|\n", | |
"| %lsmagic | List all magics |\n", | |
"| ! | Execute shell script |\n", | |
"| %who(s) | See list of variables in current kernel |\n", | |
"| %time(it)| Time a python expression <br>(w/ control over number of executions, etc.)|\n", | |
"\n", | |
"Many more built-in magic functions: http://ipython.readthedocs.io/en/stable/interactive/magics.html\n", | |
"\n", | |
"### Cell magics (%%) vs. line magics (%)\n", | |
"\n", | |
"Some magics have versions that apply to the entire cell by placing %%magic as the first line in a cell (i.e. %%timeit)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2017-10-04T03:06:14.453648Z", | |
"start_time": "2017-10-03T23:06:12.983624-04:00" | |
} | |
}, | |
"outputs": [], | |
"source": [ | |
"%timeit \",\".join(str(n) for n in range(100))" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Other cool stuff \n", | |
"\n", | |
"### Slideshow:\n", | |
"\n", | |
" jupyter nbconvert notebook.ipynb --to slides --post serve\n", | |
" \n", | |
"#### Online rendering with nbviewer: https://nbviewer.jupyter.org/\n", | |
"\n", | |
"#### Online execution with Binder: http://mybinder.org/" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3.7", | |
"language": "python", | |
"name": "python37" | |
}, | |
"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.7.4" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment