Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
DTU Compute
Technical University of Denmark
March 1, 2017
Jupyter
What is Jupyter?
Project Jupyter
Originally a spin-out of IPython,
— an interactive shell (and from
that formerly called IPython
Notebook)
Homepage: https://jupyter.org/
Installation
i.e., Jupyter is available as a package from the Python package index, see
https://pypi.python.org/pypi/jupyter/.
After installation your should be ready to start the Jupyter from the
command-line:
jupyter notebook
Starting Jupyter
Client-Server model: The client is the webbrowser that sends and receives
from a (possibly remote) Python webserver to the kernel.
Start jupyter from the command line (in the working directory where you
want to work from):
jupyter notebook
This will start the server and spawn a browser that is used for editing.
Text in Jupyter
Cell-oriented editing.
Code
Default to Python.
Kernels
For the Python kernel there are a number of different magic commands
beyond matplotlib
There are different versions, so old Jupyter versions might not be able to
read new versions.
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from __future__ import division\n",
"\n",
"from afinn import Afinn\n",
"import numpy as np\n",
...
url = ( " https :// raw . git hubu ser con ten t . com / fnielsen / afinn / "
" master / notebooks / "
" CrowdFlower %20 Twitter %20 sentiment %20 analysis . ipynb " )
notebook = requests . get ( url ). json ()
print ( " " . join ( notebook [ ’ cells ’ ][0][ ’ source ’ ]))
In [3]: df = read_csv(expanduser('~/data/7K9268/7K9268ExtModeSdecoded.csv'))
In [4]: df.tail(5)
nbconvert. 2013
2014
-26240
-26432
351.7
349.2
62
47
256
256
1012
1012
32000
32000
0
0
26400
26400
oat
2010 -42
2011 -42
2012 -42
You can embed other content than text and code in a notebook.
Note that viewers night not be able (or want to) to display the embedded
content, see, e.g., Nielsen2017Jupyter embeddings.ipynb on Github where
GitHub does not display the YouTube video or the iframe.
Slideshows
Live slideshows
The RISE notebook extension
should be install for this func-
tionality.
“A bound notebook”?
“A bound notebook”?
“A bound notebook”?
Consider a file:
$ sha512sum N i e l s e n 2 0 1 7 J u p y t e r _ s e c r e t . ipynb
86 d 3 5 5 9 4 2 b 9 5 a 3 6 d 7 2 3 d 9 4 d 5 0 e 7 8 c 3 d 2 a 3 6 4 2 c 0 6 d b f f 4 c 2 3 7 0 4 ...
And publish the checksum. But the author and the date is still dangling.
Jupyter Notebooks can be used with git (or other revision control system).
Just checkin the notebook file as a normal file (after creation of the
repository):
git add N i e l s e n 2 0 1 7 J u p y t e r _ s i m p l e . ipynb
git commit N i e l s e n 2 0 1 7 J u p y t e r _ s i m p l e . ipynb
git push
Standard Jupyter notebook has no time stamps and no author. Git has
that for you.
The cloud-based git provider GitHub is able to format the notebook file
for you.
Git diff
A Git diff on GitHub for an R notebook change.
Cloud-based?
Not really good for storing and editing data (input data, intermediate
computation, or output) for you. This is not a spreadsheet.
Notebook examples
Thanks
References
(2014). Danish Code of Conduct for Research Integrity. Ministry of Higher Education and Science,
Copenhagen, Denmark.
Kanare, H. M. (1985). Writing the Laboratory Notebook. American Chemical Society.
Kluyver, T., Ragan-Kelley, B., Pérez, F., Granger, B., Bussonnier, M., Frederic, J., Kelley, K., Hamrick, J.,
Grout, J., Corlay, S., Ivanov, P., Avila, D., Abdalla, S., Willing, C., and Team, J. D. (2016). Jupyter Note-
books – a publishing format for reproducible computational workflows. pages 87–90. DOI: 10.3233/978-
1-61499-649-1-87.