Jupyter Notebook supports Markdown. This lesson will cover some of the things you can do using Markdown to interlace your thoughts and code in Notebooks to tell compelling stories about your data. You’ll see how to format text, add syntax highlighting, make lists, and other ways to make text presentable.
Markdown Formatting in Jupyter Notebooks
00:00 In this next part of the tutorial, I want to talk about Markdown formatting, which is something that makes Jupyter Notebooks very exciting because you can easily interlace thoughts and code together, and even have those written thoughts formatted nicely to create a Notebook that tells your data story compellingly.
00:41 Or, the third way that you can do it is using the keyboard shortcut—that’s how I usually do it. If you just type m then it converts it to Markdown. And you can know by this In writing here on the left side—it’s gone when it’s a Markdown cell.
01:09 This is not really a Markdown tutorial, so I’m just going to go over it quickly, but I want to show you all the possibilities that you have. You can make headings, you can make subheadings, this can go further down… a smaller heading. And if you run those—let’s actually look at this.
01:31 When I run this, it converts to HTML and gets displayed in this way that looks nice already, just by itself. And it’s very easy to write. You can write normal text—that’s going to get converted to normal text.
01:52 And then you can also create formatting with text. Here are some examples for that. We have text attributes like italic, bold, or monospace—which is very useful if you write some code—and there’s also the possibility to write code blocks in there.
So, this is kind of interesting because you’re inside of a Jupyter Notebook, inside of a Markdown block, and then you create a little code block that correctly syntax highlights your Python code if you add this
python to the end of the triple backticks (
Let’s take a look. You can see the text gets italic, bold, formatted as code, and in here, we even have syntax highlighting inside of code blocks. And there’s more things you can do—you can create bulleted lists with stars (
*), or with pluses (
+), or with minuses (
02:56 You can add a horizontal rule. The bulleted list formats nicely and the numbered list does as well. And you can also add links. This is the way that Markdown creates links. You can link images in here.
03:21 And this actually nicely displays the image right inside of our Notebook. So we can even embed images, and we can have links that show up as links, et cetera, et cetera. There’s a lot you can do. You can even use inline HTML.
03:40 So, that’s just a quick overview of what you can do with Markdown inside of here. The exciting part really is that you can have these cells interlaced with code cells. So up here, we have an actual code cell that can execute and print something, then we have a Markdown cell that can have some sort of story or a description of what’s going on. I can create a new code cell just below, write some more code…
04:09 and execute it. I can have some more text happening, I can have another code block where I—for example—print out my variable. And I hope you can see that with this you can craft very compelling stories that can show your data exploration, for example, in a way that’s easy to follow for people who are reading over this.
04:30 This is especially great for sharing thoughts and discoveries in the scientific community, but it can be extremely useful also for creating a presentation when you did some investigation on a dataset for a business that you might be contracting for or working for.
04:45 And it’s just a simple way of making it look nice while keeping the code and the story together in one thing. So, in the next section, we’re going to look at some a little more advanced features, and we’re going to start off with, “Okay, we have a finished document. What can we export it to, and how do we do that?”
Become a Member to join the conversation.