User:SKaret/Notebook/GroupProj/NotesJupyter

From OpenWetWare
Jump to navigationJump to search

Project Wiki Home

Jupyter Notebook Notes

Intro to Jupyter Notebook

Pythons Jupyter Notebook:

  • Allows us to program in a web browser.
  • Is a mix of code, instructions and output; all of this information is displayed 'in line' in one web page.
  • It is used by Scientists and Researchers, and is very useful for writing code that 'tells a story'.
  • Not useful for writing an application.

The files that Jupyter creates/opens are ipynb files (i python notebook file).


Kernal: A programming environment. Jupyter by default runs Python, but there are Jupyter Kernals for many other programming languages e.g. R, Java and Scala.

ie a Kernal is basically what programming language we want to use.

Examples of Notebooks can be found at:

https://github.com/jupyter/jupyter/wiki/A-gallery-of-interesting-Jupyter-Notebooks

This link may be useful to help us with the Modelling aspect.

The Jupyter Notebook Environment

If we click a box (cell) it turns green.

EditMode.png

We are then in edit mode and can write the program.

In [*] means that the current cell is running.

In [x] where x is a number represents the execution order of the cells.

When the * becomes a number it finishes running.

Blue: Means we are in command mode.

CommandMode.png

Hit esc key on keyboard to go to command mode.

Command mode: press button to most right to get a list of commands.

Example of a Command: turn line numbers on. press Esc and then l when clicked on the cell.

If one cell is still running, and we edit a second cell and try to run it it won't work.


We have to either make the cell finish running or restart the Kernal to solve the problem- Press the restart Kernal button.


When finished with the Jupyter Notebook, go to file --> Close and Halt to quit app and terminate the Kernal


Note: If a cell later on uses a variable or class from a previous cell, we must run the previous cell before running this cell so that it is in memory.

Going on Cell ---> Cell Type ----> Markdown can allows us to add Markdown language into the code to the notebook - we can then explain any concepts that we need to in that cell.

Magic Commands:

% - the commands arguments will all come from that same line. (Line Magics)
%% - the entire cell will be used as that commands arguments. (Cell Magics)

e.g. %lsmagic is a magic command that will list all the Magic Commands.

More examples are in the youtube tutorials.

%pwd - magic command that will print working directory.

Exporting

  • Going to file---> Download as allows us to export the file in many different ways.
  • e.g. HTML, can allow us to post in a blog...or something similar.
  • The ipynb file is like a Json file- it contains all the info needed

Modelling in Python: What we need to know