Skip to content

Jupyter Notebook

Comprehensive Jupyter Notebook shortcuts and workflows for data science and interactive computing.

Basic Navigation

ShortcutModeDescription
EnterCommandEnter Edit Mode
EscEditEnter Command Mode
Shift+EnterBothRun Cell and Select Below
Ctrl+EnterBothRun Cell
Alt+EnterBothRun Cell and Insert Below
↑/↓CommandSelect Cell Above/Below
ACommandInsert Cell Above
BCommandInsert Cell Below
XCommandCut Cell
CCommandCopy Cell
VCommandPaste Cell Below
Shift+VCommandPaste Cell Above
DDCommandDelete Cell
ZCommandUndo Cell Deletion

Cell Operations

ShortcutModeDescription
MCommandChange to Markdown Cell
YCommandChange to Code Cell
RCommandChange to Raw Cell
1-6CommandChange to Heading 1-6
Shift+MCommandMerge Selected Cells
Ctrl+Shift+-EditSplit Cell at Cursor
Shift+J/KCommandExtend Selection Below/Above
Shift+↑/↓CommandExtend Selection

Code Editing

ShortcutModeDescription
TabEditCode Completion or Indent
Shift+TabEditTooltip
Ctrl+]EditIndent
Ctrl+[EditDedent
Ctrl+AEditSelect All
Ctrl+ZEditUndo
Ctrl+Shift+ZEditRedo
Ctrl+YEditRedo
Ctrl+HomeEditGo to Cell Start
Ctrl+EndEditGo to Cell End
Ctrl+Left/RightEditGo Left/Right One Word
Ctrl+BackspaceEditDelete Word Before
Ctrl+DeleteEditDelete Word After

Running Code

ShortcutModeDescription
Shift+EnterBothRun Cell, Select Below
Ctrl+EnterBothRun Cell
Alt+EnterBothRun Cell, Insert Below
Ctrl+KCommandInterrupt Kernel
0,0CommandRestart Kernel
Shift+LCommandToggle Line Numbers
Shift+OCommandToggle Output

File Operations

ShortcutModeDescription
Ctrl+SBothSave and Checkpoint
Ctrl+Shift+SCommandSave As
Ctrl+OCommandOpen
Ctrl+NCommandNew Notebook
Ctrl+Shift+PCommandCommand Palette

View and Layout

ShortcutModeDescription
Shift+SpaceCommandScroll Up
SpaceCommandScroll Down
Ctrl+Shift+LCommandToggle All Line Numbers
FCommandFind and Replace
OCommandToggle Output
Shift+OCommandToggle Output Scrolling

Magic Commands

CommandDescription
%run script.pyRun Python script
%load script.pyLoad script into cell
%whoList variables
%whosList variables with details
%time statementTime execution of statement
%timeit statementTime execution multiple times
%matplotlib inlineEnable inline plots
%pwdPrint working directory
%cd directoryChange directory
%lsList directory contents
%historyShow command history
%resetReset namespace
%debugEnter debugger
%pdb on/offToggle automatic debugger

Cell Magic Commands

CommandDescription
%%timeTime execution of entire cell
%%timeitTime execution of cell multiple times
%%bashRun cell as bash script
%%htmlRender cell as HTML
%%javascriptRun cell as JavaScript
%%latexRender cell as LaTeX
%%markdownRender cell as Markdown
%%python2Run cell with Python 2
%%python3Run cell with Python 3
%%writefile filenameWrite cell contents to file

Data Science Workflows

Data Loading and Exploration

python
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

# Load data
df = pd.read_csv('data.csv')

# Quick exploration
df.head()
df.info()
df.describe()
df.shape

Data Visualization

python
# Matplotlib inline
%matplotlib inline

# Basic plots
plt.figure(figsize=(10, 6))
plt.plot(x, y)
plt.title('Title')
plt.xlabel('X Label')
plt.ylabel('Y Label')
plt.show()

# Seaborn plots
sns.scatterplot(data=df, x='col1', y='col2')
sns.heatmap(df.corr(), annot=True)

Machine Learning Pipeline

python
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error

# Prepare data
X = df[['feature1', 'feature2']]
y = df['target']

# Split data
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)

# Train model
model = LinearRegression()
model.fit(X_train, y_train)

# Evaluate
predictions = model.predict(X_test)
mse = mean_squared_error(y_test, predictions)

Markdown Formatting

Headers

markdown
# Header 1
## Header 2
### Header 3
#### Header 4
##### Header 5
###### Header 6

Text Formatting

markdown
**Bold text**
*Italic text*
`Code text`
~~Strikethrough~~

Lists

markdown
- Unordered list item 1
- Unordered list item 2

1. Ordered list item 1
2. Ordered list item 2
markdown
[Link text](URL)
![Alt text](image_url)

Tables

markdown
| Column 1 | Column 2 | Column 3 |
|----------|----------|----------|
| Row 1    | Data     | Data     |
| Row 2    | Data     | Data     |

Math (LaTeX)

markdown
Inline math: $E = mc^2$

Block math:
$$\int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi}$$

Best Practices

Code Organization

  • Use meaningful variable names
  • Add comments and docstrings
  • Break complex operations into multiple cells
  • Use functions for repeated operations
  • Import libraries at the top

Data Analysis Workflow

  1. Data Loading: Import and initial exploration
  2. Data Cleaning: Handle missing values, outliers
  3. Exploratory Data Analysis: Visualizations and statistics
  4. Feature Engineering: Create new features
  5. Modeling: Train and evaluate models
  6. Results: Interpret and visualize results

Performance Tips

  • Use vectorized operations with NumPy/Pandas
  • Avoid loops when possible
  • Use appropriate data types
  • Clear output of large cells
  • Restart kernel periodically

Documentation

  • Use Markdown cells for explanations
  • Document assumptions and decisions
  • Include data source information
  • Add conclusions and next steps
  • Use clear section headers