Jupyter Notebook
Jupyter notebooks
What is Jupyter Notebook?
-
A web-based interactive development environment
Jupyter on Windows
If you use Anaconda it already comes with Jupyter notebook. On Windows you can run it from the start menu.
Alternatively:
pip install jupyter
Jupyter on Linux and OSX
Install
For Linux and OSX I recommend using virtualenv and installing with pip.
virtualenv -p python3 ~/venv3
source ~/venv3/bin/activate
pip install jupyter
Run
cd examples/jupyter/
jupyter notebook
- Your browser should open. If not, there is a link in the terminal.
Jupyter New notebook
-
Create new notebook (New / Python 3)
-
It is called "Untitled" - Rename it
-
Type in some code
x = 2
-
Execute code
-
Show content of variables
-
import modules
-
Quit - shut down the notebook server.
-
Number is the execution order Out[] refers to the number of the cell for this this the output.
Jupyter Notebook file format
- Jupyter file format (show the file) JSON
- Download file as Python (.py)
Jupyter notebook edit and command mode
-
Modes: Blue - command mode, Green - edit mode
-
Enter - Switch to edit mode (or newline if already in edit mode)
-
ESC - Switch to command mode
-
Ctrl-Enter - execute current cell
-
Shift-Enter - execute current cell
-
Clear Cell data before saving
-
Button h for help
-
Button A - add cell Above current cell
-
Button B - add cell Below current cell
-
dd - delete current cell
-
...
Jupyter notebook Intellisense (TAB completition)
- Just press TAB for word completition and method suggestions
Jupyter add
- Open an existing notebook:
add.ipynb
Planets
-
The Planets example we saw in the Pandas chapter
-
planets.csv
-
planets.ipynb
Jupyter input
name = input("Name: ")
File chooser
- Avoid hard-coded pathes
FileChooser.ipynb
IPy Widgets
ipywidgets
-
ipywidgets.ipynb
Jupyter Notebook and Markdown
markdown.ipynb
- Jupyter Markdown
- Original Markdown
- Markdown
Latex in Jupyter Notebook
- To insert complex formulas.
latex.ipynb
- Latex symbols
Jupyter StackOverflow
-
Download a dataset from the Stack Overflow survey.
-
unzip the file. Feel free to remove the
__MACOSX/
directory if it is included. -
SO/so.ipynb
-
SO/selected-rows.ipynb
-
SO/selected-columns.ipynb
Use SciPy image
scipy_image.ipynb
Create Random image
create_random_image.ipynb
Load image using OpenCV
-
load_image_using_opencv
Genes using Jupyter
jupyter notebook genes.ipynb
More Jupyter examples
generate.ipynb
Generate a single Pandas DataFramesalary_generate.ipynb
salary.ipynb
temperatures.ipynb
weather.ipynb
numpy_matrix.ipynb
seaborn_tips.ipynb
Jupyter Notebook: run on other port
jupyter notebook --port 8080
Jupyter Notebook: public IP
jupyter notebook --ip 192.168.1.10
Other Jupyter Notebook Kernels
Jupyter Notebook convert to other format (nbconvert)
- nbconvert
jupyter nbconvert try.ipynb --to HTML
jupyter nbconvert try.ipynb --to PDF (needs also pandoc)
Jupyter Notebook extensions
pip install jupyter_contrib_nbextensions
pip install jupyter_nbextensions_configurator
jupyter nbextensions_configurator enable --user
- Scratchpad
- Variable Inspector
Jupyter notebook Checkpoints
- A very simple, one-level version control.
- I would not rely on it as it is now. Use a real VCS. (e.g. git)
Jupyter notebook autoreload
def hello():
print("hello")
examples/ml/reload.ipynb