From the course: Introducing Jupyter
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Cell magic commands - Python Tutorial
From the course: Introducing Jupyter
Cell magic commands
- [Instructor] A cell magic command works on the contents of the entire cell. The magic command does need to be at the top of the cell for it to work. There's an importance difference in calling line magics versus cell magics. Which is that the cell magic must be pre-pended by a double percent sign. Some of the magic commands work as either line or cell magics depending on how they're called. The first cell magic we'll look at is write file. Let's say I write a function that will get the mean of whichever column I pass into it. I think that function could come in handy later, so I want to save it to a file. I can type in the write file command at the top of the cell along with a file name to write to. And that will write to the file that I gave it. I can verify that by calling cat on that file. Let's take a look at another magic called capture. Similar to the write file command, I'll put a capture at the top of the cell followed by a variable name. Now I'll add in another line that…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.