Today, I googled for ways to insert Jupyter Notebooks in Jekyll blogs and found that in general, there are two ways. The most recent development, if I’m not mistaken, is the use of the jekyll-jupyter-notebook plugin. The most common and the older way is to convert the notebook to a markdown file via a command line tool or by using the available option in Jupyter notebooks (download as markdown file).

I tested the plugin by following the instructions from here (by Red Data Tools). This didn’t work very well for me despite surrounding the Liquid tag markup for the notebook with {::nomarkdown} {:/nomarkdown} tags.

I think it would be cool if that worked because it really does look like the Jupyter notebook rendered on the Jekyll blog.

The easiest way to incorporate Jupyter notebooks is explained in this blog by Linode. It involves copying the converted Jupyter notebook to markdown and inserting them into the post. This, however, merely looked like how you would usually create code snippets. The following is an example of how this would look like:

import pandas as pd
import seaborn as sns
%matplotlib inline

url = "https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data"
names = ['sepal-length', 'sepal-width', 'petal-length', 'petal-width', 'class']
iris = pd.read_csv(url, names=names)

iris.head()
iris.describe()

sns.pairplot(x_vars=["petal-length"], y_vars=["petal-width"], data=iris, hue="class", size=10)
<seaborn.axisgrid.PairGrid at 0x1083cba20>

png

iris.head()
sepal-length sepal-width petal-length petal-width class
0 5.1 3.5 1.4 0.2 Iris-setosa
1 4.9 3.0 1.4 0.2 Iris-setosa
2 4.7 3.2 1.3 0.2 Iris-setosa
3 4.6 3.1 1.5 0.2 Iris-setosa
4 5.0 3.6 1.4 0.2 Iris-setosa

I still like how the jekyll plugin looks like, though, only if the formatting of the page doesn’t get messed up.