10 Hidden Jupyter Notebook Tricks That Can Save You an Hour Every Day
Discover ten lesser‑known Jupyter Notebook features—from magic commands that list variables and benchmark code to shortcuts, export utilities, and interactive help—that turn a simple notebook into a highly efficient, production‑ready data‑science workspace.
Many data practitioners use Jupyter merely as a code‑scratchpad, running cells manually and relying on comments for documentation. This guide reveals ten hidden Jupyter features that dramatically improve debugging, performance testing, workflow automation, and report generation.
1. Variable "Locator" (%who & %whos)
Quickly list all variables in the current namespace with %who, or display a detailed table of variable names, types, sizes, and values using %whos.
import numpy as np
data = np.array([1, 2, 3])
%whos # output: data numpy.ndarray (3,) [1 2 3]2. Speed "Judge" (%timeit)
Measure execution time of a single expression or an entire cell. Use %timeit for a one‑liner and %%timeit for the whole cell.
%timeit [i**2 for i in range(1000)] # list comprehension
%timeit np.square(np.arange(1000)) # NumPy vectorized operation3. Terminal "Connector" (! command)
Run shell commands directly from a notebook cell without leaving the interface.
!ls # list files in the current directory
!pip install pandas -i https://pypi.tuna.tsinghua.edu.cn/simple # accelerated install
!cat data.csv # preview a CSV file4. Code "Exporter" (%%writefile)
Save the contents of a cell to a .py file with a single magic command.
%%writefile my_utils.py
def clean_data(df):
return df.dropna().reset_index(drop=True)Verify the export with !cat my_utils.py.
5. Syntax "Dictionary" (? and ??)
Use object? to display a quick summary of a function’s signature and docstring, and object?? to view the full source code when available.
len? # shows parameters and return type
pd.DataFrame?? # shows the implementation of the DataFrame class6. Shortcut Trio (Shift+Enter, Ctrl+Enter, Alt+Enter)
Shift+Enter – run the cell and move to the next one.
Ctrl+Enter – run the cell and stay in place.
Alt+Enter – run the cell and insert a new cell below.
7. Markdown "Beautifier"
Leverage Markdown syntax to turn notebook notes into polished documents, including headings, numbered lists, LaTeX formulas, and embedded images.
# Heading 1 (Report Title)
## Heading 2 (Section Title)
- 1. Data cleaning
- 2. Model training
- $y = wx + b$ (linear regression)
- 8. Large‑Note "Collapser"
Install the jupyter_contrib_nbextensions package and enable the "Collapsible Headings" extension to fold sections, reducing visual clutter in notebooks with hundreds of lines.
pip install jupyter_contrib_nbextensions # install extensions
jupyter contrib nbextension install --user # enable
# In Jupyter Notebook UI, check "Collapsible Headings"
# In JupyterLab (>=3.0), install via the Extension Manager.9. Export "Cleaner" (nbconvert + tags)
Tag cells to control what gets exported. Use tags like remove_input, remove_output, and remove_cell with nbconvert to produce clean HTML or PDF reports.
# Add tags via View → Cell Toolbar → Tags
# Example tags: remove_input, remove_output, remove_cell
# Export commands
jupyter nbconvert --to html --TagRemovePreprocessor.remove_input_tags="{'remove_input'}" notebook.ipynb
jupyter nbconvert --to pdf --TagRemovePreprocessor.remove_cell_tags="{'remove_cell'}" notebook.ipynb10. Smart "Suggester" (Tab Completion & Shift+Tab)
Press Tab to autocomplete variable or function names, and Shift+Tab to display the docstring tooltip for the object under the cursor.
Auto‑complete: type df. then Tab to see all DataFrame methods.
Shift+Tab: shows the function signature and description without leaving the notebook.
These hidden features collectively turn Jupyter into a powerful, production‑ready environment for data exploration, analysis, and reporting.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Data Party THU
Official platform of Tsinghua Big Data Research Center, sharing the team's latest research, teaching updates, and big data news.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
