Back to basics — Jupyter notebooks

Snehal Gawas
Aug 8, 2017 · 4 min read

Jupyter notebooks provide an effective way to develop, document, execute and communicate your results. Here are few tips and tricks to make your life easier while working on notebooks in Data Science Experience.

Notebooks modes

Jupyter notebooks have two different modes, EDIT and COMMAND.

Edit mode:
To enter the EDIT mode, press ENTER on your keyboard or click in a cell. Edit mode can be identified by green border around the cell with green left margin. When you are in the edit mode, you can type in the cells.

Command mode:
To enter the COMMAND mode press ESC or click anywhere outside the cell. You will see grey border around the cell with blue left margin. When you are in Command mode, you can edit your notebook but you can't type in the cells.

Navigation in the notebook

You can perform different actions on notebooks using your MOUSE or KEYBOARD.

Mouse navigation:
You can use mouse to perform any action on your notebook from Menu bar or Tool bar as per your preference.

Keyboard navigation:
Those who prefer keyboard can use keyboard shortcuts. Here are few examples of keyboard shortcuts.

  • Command Mode: ESC
  • Edit Mode: ENTER
  • Run selected cell: CTRL+ENTER
  • Run cell and insert below: ALT+ENTER
  • Run cell and select below: SHIFT+ENTER
  • Insert cell above: A
  • Insert cell below: B
  • Cut selected cells: X
  • Copy selected cells: C

For more keyboard shortcuts, you can refer Help -> Keyboard Shortcuts from Menu bar.

Magic in the notebook

Do you know, you can run code in different languages in different cells within your notebook? If you want to see what all magic commands you can use within your notebook, just run %lsmagic in one of the cells.

Use % matplotlib inline to show matplotlib plots inline the notebook.

Use %%writefile to write content of the cell to a file and %run before the name of the file to execute the script.

Few other examples of cell magic:

  • To render cell contents as LaTeX: %%latex
  • To render cell contents as Html: %%HTML
  • To run cell with bash commands: %%bash

You can try different commands from above list and experiment with magic.

Finally, if you need any help in the notebook just type in your function name and append ?. Notebook will give you required information about function with example.

Additionally, there are features in Jupyter to help with code completion. For example, if you need to see parameters for a function inside a notebook, after you open the parentheses for the function call you can press SHIFT+TAB to show the docstring.

You can also use code completion to help end names of variables or functions in your environment by starting to type the name of the object and pressing TAB.

To test out these tips and tricks sign up for a for a free trial of Data Science Experience. For more informative blogs, keep an eye on Data Science Experience blog. Feel free to share your notebook on social media and don’t forget to add your friends in your project as collaborators.

Happy exploring Data Science Experience!

Originally published at datascience.ibm.com on August 8, 2017.

IBM Watson Data

Build smarter applications and quickly visualize, share, and gain insights

Snehal Gawas

Written by

IBM Watson Data

Build smarter applications and quickly visualize, share, and gain insights

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade