Lesson 6. Useful Jupyter Notebook Shortcuts


Learning Objectives

  • List useful keyboard shortcuts in Jupyter Notebook.
  • Be able to access the list list of keyborad shortcuts in Jupyter Notebook.

List of Useful Jupyter Notebook Shortcuts

As you have seen in this chapter, you can manipulate your Jupyter Notebook using the drop-down tools from the menu, with keyboard shortcuts, or using both.

The table below lists common tasks in Jupyter Notebook and how to do them using keyboard shortcuts or the menu tool.

FunctionKeyboard ShortcutMenu Tools
Save notebookEsc + sFile → Save and Checkpoint
Create new cellEsc + a (above), Esc + b (below)Insert→ cell above Insert → cell below
Run CellCtrl + enterCell → Run Cell
Copy CellcCopy Key
Paste CellvPaste Key
Interrupt KernelEsc + i iKernel → Interrupt
Restart KernelEsc + 0 0Kernel → Restart
Find and replace on your code but not the outputsEsc + fN/A
merge multiple cellsShift + MN/A
When placed before a function Information about a function from its documentation?N/A

For a full list of keyboard shortcuts, click the help button, then the keyboard shortcuts button.

Help menu of Jupyter Notebook.
Help menu of Jupyter Notebook.

Practice Your Jupyter Notebook Skills

Test your Jupyter Notebook skills to:

  1. Launch Jupyter Notebook from your earth-analytics directory.

  2. Create a new Jupyter Notebook file called jupyter-notebook-interface.ipynb.

  3. Add a Code cell and copy/paste the following Python code to determine which day had the most precipitation (i.e. the day of the greatest flooding) during the Fall 2013 flood in Boulder, CO, U.S.A.

# Import necessary packages
import matplotlib.pyplot as plt
import pandas as pd

# Create data
boulder_precip = pd.DataFrame(columns=["date", "precip"], 
                              data=[
                                  ["2013-09-09", 0.1], ["2013-09-10", 1.0], 
                                  ["2013-09-11", 2.3], ["2013-09-12", 9.8], ["2013-09-13", 1.9],
                                  ["2013-09-14", 0.01], ["2013-09-15", 1.4], ["2013-09-16", 0.4]])      
# Create plot
fig, ax = plt.subplots()
ax.bar(boulder_precip['date'].values, boulder_precip['precip'].values)
ax.set(title="Daily Precipitation (inches)\nBoulder, Colorado 2013", 
       xlabel="Date", ylabel="Precipitation (Inches)")
plt.setp(ax.get_xticklabels(), rotation=45);
  1. Run the Python cell.

You have now experienced the benefits of using Jupyter Notebook for open reproducible science!

Without writing your own code, you were able to easily replicate this analysis because this code block can be shared with and run by anyone using Python in Jupyter Notebook.

  1. Add a Code cell and run each of the following Python calculations:
    • 16 - 4
    • 24 / 4
    • 2 * 4
    • 2 ** 4
      • What do you notice about the output of 24 / 4 compared to the others?
      • What operation does ** execute?
  2. Create a new directory called chap-3 in your earth-analytics directory.

  3. Create a new directory called test in your earth-analytics directory and move it into in the newly created directory called chap-3.

  4. Delete the test directory - do you recall how to find the test directory in its new location?

  5. Rename the Jupyter Notebook file that you created in step 2 (e.g. jupyter-notebook-interface.ipynb) using your first initial and last name (e.g. jpalomino-jupyter-notebook-interface.ipynb).

  6. Create a new folder called chap-3 in your earth-analytics directory.

  7. Move your renamed Jupyter Notebook file (e.g. jpalomino-jupyter-notebook-interface.ipynb) into the new chap-3 directory.

Leave a Comment