Jupyter - Hotkeys Flashcards

1
Q

Esc

A

Esc will take you into command mode where you can navigate around your notebook with arrow keys.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

A

A

A to insert a new cell above the current cell

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

B

A

B to insert a new cell below

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

M

A

M to change the current cell to Markdown

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Y

A

Y to change it back to code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

D + D

A

D + D (press the key twice) to delete the current cell

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Enter

A

Enter will take you from command mode back into edit mode for the given cell.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Shift + Tab

A

Shift + Tab will show you the Docstring (documentation) for the the object you have just typed in a code cell - you can keep pressing this short cut to cycle through a few modes of documentation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Ctrl + Shift + -

A

Ctrl + Shift + - will split the current cell into two from where your cursor is

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Esc + F

A

Esc + F Find and replace on your code but not the outputs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Esc + O Toggle cell output.

A

Toggle cell output.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Shift + Down

Shift + Up

A

Shift + J or Shift + Down selects the next sell in a downwards direction. You can also select sells in an upwards direction by using Shift + K or Shift + Up.

(Once cells are selected, you can then delete / copy / cut / paste / run them as a batch. This is helpful when you need to move parts of a notebook.)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Shift + M

A

You can also use Shift + M to merge multiple cells.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

?[insert library, method, or variable here]

A

Don’t forget also that by prepending a library, method or variable with ?, you can access the Docstring for quick reference on syntax.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

%run [insert .py or .ipynb file here]

A

%run can execute python code from .py files - this is well-documented behavior. Lesser known is the fact that it can also execute other jupyter notebooks, which can quite useful.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

%load [insert script file or URL here]

A

This will replace the contents of the cell with an external script. You can either use a file on your computer as a source, or alternatively a URL.

17
Q

%%time

A

%%time will give you information about a single run of the code in your cell.

18
Q

%%timeit

A

%%timeit uses the Python timeit module which runs a statement 100,000 times (by default) and then provides the mean of the fastest three times.

19
Q

%%writefile

%pycat

A

Using the %%writefile magic saves the contents of that cell to an external file. %pycat does the opposite, and shows you (in a popup) the syntax highlighted contents of an external file.

20
Q

%pdb

A

Jupyter has own interface for The Python Debugger (pdb). This makes it possible to go inside the function and investigate what happens there.

21
Q

adding a ; to end of line

A

Sometimes it’s handy to suppress the output of the function on a final line, for instance when plotting. To do this, you just add a semicolon at the end.

22
Q

It’s easy to execute a shell command from inside your notebook. You can use this to check what datasets are in available in your working folder…

A

!ls *.csv

23
Q

It’s easy to execute a shell command from inside your notebook…like to check and manage packages

A

!pip install numpy

!pip list | grep pandas

24
Q

Just use IPython Magics with the name of your kernel at the start of each cell that you want to use that Kernel for…

A

%%bash

%%HTML

%%python2

%%python3

%%ruby

%%perl

25
Q

Running R and Python in the same notebook.

A

The best solution to this is to install rpy2 (requires a working version of R as well), which can be easily done with pip.

pip install rpy2

You can then use the two languages together, and even pass variables inbetween:

%load_ext rpy2.ipython

%R require(ggplot2)

array([1], dtype=int32)

import pandas as pd
df = pd.DataFrame({
‘Letter’: [‘a’, ‘a’, ‘a’, ‘b’, ‘b’, ‘b’, ‘c’, ‘c’, ‘c’],
‘X’: [4, 3, 5, 2, 1, 7, 7, 5, 9],
‘Y’: [0, 4, 3, 6, 7, 10, 11, 9, 13],
‘Z’: [1, 2, 3, 1, 2, 3, 1, 2, 3]
})

%%R -i df
ggplot(data = df) + geom_point(aes(x = X, y= Y, color = Letter, size = Z))