Cell Magic Functions
Cell Magic functions are special commands that allow the user to modify the behaviour of a code cell explicitly. Cell Magic functions have the prefix ‘%%’ followed by the command name. Cell magic functions serve various tasks and customizations which we discuss thoroughly further in this article.
Advantages of Cell Magic Functions
Limitations of Cell Magic Functions
- Dependencies of different kernels or environment
- Ambiguity occurs if too many cell magics are used and can cause potential conflicts
- Hard to remember the syntax of different cell magic functions
Table of Cell Magic Functions
Cell Magic Function |
Description |
---|---|
%%bash |
Run cells with bash in a subprocess. |
%%capture |
run the cell, capturing stdout, stderr, and IPython’s rich display() calls. |
%%html |
Render the cell as a block of HTML |
%%javascript or %%js |
Run the cell block of Javascript code |
%%latex |
Render the cell as a block of LaTeX |
%%markdown |
Render the cell as Markdown text block |
%%perl |
Run cells with perl in a subprocess. |
%%pypy |
Run cells with pypy in a subprocess |
%%python |
Run cells with python in a subprocess |
%%python2 |
Run cells with python2 in a subprocess. |
%%python3 |
Run cells with python3 in a subprocess |
%%ruby |
Run cells with ruby in a subprocess |
%%script |
Run a cell via a shell command |
%%sh |
Run cells with sh in a subprocess |
%%svg |
Render the cell as an SVG literal |
%%writefile |
Write the contents of the cell to a file. |
Jupyter Notebook – Cell Magic Functions
In this article, we will cover Cell Magic Functions in Jupyter Notebook we will discuss various functions. But first, we look at what Jupyter Notebook and Cell Magic functions and why we use them. There are a lot of cell magic functions but in this article, we discuss the most commonly used cell magic functions.