Working with Jupyter Notebook and Python

Posted by admin at April 28, 2020

883px Jupyter logo.svg  - Working with Jupyter Notebook and Python

Jupyter Notebooks provide a balance of jotting down important summary information along with proving a live code development environment where we can write and run python code.

working in notebook cells

  • Markdown cells display text in a web page format. Markdown is code that formats the way the cell displays (this cell is Markdown)
  • Code cells contain python code and can be interpreted and run from a cell. Code cells display code and output.
  • in edit or previously run: cells can display in editing mode or cells can display results of code having been run

edit mode

  • text cells in editing mode show markdown code
  • Markdown cells keep editing mode appearance until the cell is run
  • code (python 3) cells in editing look the same after editing, but may show different run output
  • clicking another cell moves the green highlight that indicates which cell has active editing focus

cells need to be saved

  • the notebook will frequently auto save
  • best practice is to manually save after editing a cell using “Ctrl + S” or alternatively, Menu: File > Save and Checkpoint

Altering Notebook Structure

add a cell

  • Highlight any cell and then… add a new cell using Menu: Insert > Insert Cell Below or Insert Cell Above
  • Add with Keyboard Shortcut: “ESC + A” to insert above or “ESC + B” to insert below

choose cell type

  • Format cells as Markdown or Code via the toolbar dropdown or Menu: Cell > Cell Type > Code or Markdown
  • Cells default to Code when created but can be reformatted from code to Markdown and vice versa

change notebook page language

  • The course uses Python 3 but Jupyter Notebooks can be in Python 2 or 3 (and a language called R)
  • To change a notebook to Python 3 go to “Menu: Kernel > Change Kernel> Python 3”

Methods for running the code in a cell

jupyter 1024x477 - Working with Jupyter Notebook and Python
  1. Click in the cell below and press “Ctrl+Enter” to run the code
  2. Click in the cell below and press “Shift+Enter” to run the code and move to the next cell
  3. Menu: Cell
  1. > Run Cells runs the highlighted cell(s)
  2. > Run All Above runs the highlighted cell and above
  3. > Run All Below runs the highlighted cell and below


Write a Reply or Comment