This website www.ds4n6.io uses its own and third party cookies to collect information that helps to optimize your visit to their web pages. Cookies will not be used to collect personal information. You can either allow or reject their use. You can also change their settings at any time. You will find more information on our Cookie Policy page.

OK

DS4N6 Knowledge >> Tips & Tricks >> Creating a jupyter notebook programatically

Creating a jupyter notebook programatically

import nbformat as nbf

nb = nbf.v4.new_notebook()

# Text Cell ---------------------------------
text = """\
# My first automatic Jupyter Notebook
This is an auto-generated notebook."""

# Code Cell ---------------------------------
code = """\
%pylab inline
hist(normal(size=2000), bins=50);"""

# Create & Save the Notebook ----------------
nb['cells'] = [nbf.v4.new_markdown_cell(text), nbf.v4.new_code_cell(code) ]
nbf.write(nb, 'test.ipynb')

# You can run this notebook from the command line (if you want):
jupyter nbconvert --execute --inplace test.ipynb