How to Use Jupyter Notebook: A Beginner’s Tutorial

How to Use Jupyter Notebook: A Beginner’s Tutorial

In the data science community, Jupyter notebook is a popular tool with strong adoption. This article is meant to share cool tips and tricks to help you become more efficient while utilizing Jupyter notebook. 

One of the benefits of working in Jupyter Notebook is that you can have much more functionality and expression than when working directly in your terminal. This includes adding markdown to customize and style text outside of code blocks, adding mathematical equations with LaTeX, using hotkeys for shortcuts, and lastly using magic commands that come with IPython that yield greater efficiency for common tasks.

Hotkeys in Jupyter Notebook

Hotkeys or keyboard shortcuts can improve your efficiency and save time when you’re working with a new program. Instead of using your mouse which takes your hands off of the keyboard, you can access many of the common functionality with a combination of keys. Jupyter Notebook keyboard shortcuts can be accessed through help>keyboard shortcuts. You can also access them through pressing the Cmd + Shift + P keys for Mac or Ctrl + Shift + P for Linux/Windows to open the command palette. Through the palette you can search for keywords and find the command or use commands that don’t have a keyboard shortcut.

Basic Commands

  • Basic navigation: EnterShiftEnterUp/kDown/j.
  • Saving the notebook: s.
  • Change Cell types: m to change the current cell to Markdown, y to change it back to code.
  • Cell creation: a to insert a new cell above the current cell, b to insert a new cell below.
  • Cell editing: xcvdz
  • Delete Current Cell: d + d (press the key twice).
  • Kernel operations: i0 (press twice).
  • Split the current cell into two: Ctrl + Shift + .
  • Find and replace on your code: Esc + f
  • Toggle cell output: Esc + O

Magic Commands in Jupyter Notebook

There are also magic commands that can be used to when conducting data analysis in Ipython that can be highly effective when put to use. Magic commands will help you complete commonly executed tasks in your notebook, and come in two varieties; line magics and cell magics. Line magics contain a single percent symbol % prefix and work on a single line of input. Cell magics contain a double percent sign %% prefix and work on multiple lines of input. Here are some examples of magic commands:

  • %lsmagic – Return a list all magic command
  • %run: Execute external python script
  • %load: Load in a local file, URL, function, or class
  • %who: Return a list of any variables that have a certain type within the notebook.
  • %matplotlib notebook: Allow you to interactively work with plots from matplotlib.
  • %matplotlib inline: Allow you to disable interactivity with plots.
  • %%time: Show the time it took to execute the line of code. Good for checking efficiency.

Images

You can add images from your directory or from the web ![title](img/picture.png). In between the two brackets our image name will take the place of title, and within the parentheses, the file path or url will take the place of img/picture.png.

Adding external links are just like images without the exclamation point. Here is how you do it [link text](http://url)

Styling

You can get emphasized text with either one asterisk * or underscore _ around the text. For Strong styling use two asterisks ** or underscores __ around the text.

If you want to make monospace text which is good for denoting code, use a single ` called a back tick, back quote, or left quote around the text.

You can create new lines either by including a new line in the code, or using <br> inline with text. Using *** will give you a horizontal line.

For unordered lists use a hyphen - or asterisk * with a space before the text. If you want a sub bullet add a tab before the hyphen - or asterisk *.

For ordered lists, use numbers followed by a period for the items like so 1.. Tabs still work for sub ordered lists.

Help

? before the method or variable will print the help documentation.

Suppressing output of a function with ;

For plots ending with ; will suppress output and show only the plot.

Multi-Cursor with Alt + Mouse

If you want to select more than one row, multicursor functionality can be accessed with alt + mouse click.

Leave a Reply

Prev
A Few Tips For Writing Advanced Commands in Linux
A Few Tips For Writing Advanced Commands in Linux

A Few Tips For Writing Advanced Commands in Linux

Linux is a powerful, flexible operating system that is used on a wide range of

Next
Analyzing Web Apps with Chrome’s DevTools (Hacking API’s)
Analyzing Web Apps with Chrome’s DevTools (Hacking API’s)

Analyzing Web Apps with Chrome’s DevTools (Hacking API’s)

Chrome’s DevTools is a suite of developer tools built into the Chrome browser

You May Also Like