Archie  Clayton

Archie Clayton

1559378831

Set Your Jupyter Notebook up Right with this Extension

In the great talk “I Don’t Like Notebooks” (video and slides), Joel Grus lays out numerous criticisms of Jupyter Notebooks, perhaps the most popular environment for doing data science. I found the talk instructive — when everyone thinks something is great, you need people who are willing to criticize it so we don’t become complacent. However, I think the problem isn’t the notebook itself, but how it’s used: like any other tool, the Jupyter Notebook can be (and is) frequently abused.

Thus, I would like to amend Grus’ title and state “I Don’t Like Messy, Untitled, Out-of-Order Notebooks With No Explanations or Comments.” The Jupyter Notebook was designed for literate programming — mixing code, text, results, figures, and explanations together into one seamless document. From what I’ve seen, this notion is often completely ignored resulting in awful notebooks flooding repositories on GitHub:

Don’t let notebooks like this get onto GitHub.

The problems are clear:

  • No title
  • No explanations of what the code should do or how it works
  • Cells run out of order
  • Errors in cell output

The Jupyter Notebook can be an incredibly useful device for learning, teaching, exploration, and communication (here is a good example). However, notebooks like the above fail on all these counts and it’s nearly impossible to debug someone else’s work or even figure out what they are trying to do when these problems appear. At the very least, anyone should be able to name a notebook something helpful, write a brief introduction, explanation, and conclusion, run the cells in order, and make sure there are no errors before posting the notebook to GitHub.

Solution: The Setup Jupyter Notebook Extension

Rather than just complaining about the problem (it’s easy to be a critic but a lot harder to do something positive) I decided to see what could be done with Jupyter Notebook extensions. The result is an extension that on opening a new notebook automatically:

  • Creates a template to encourage documentation
  • Inserts commonly used library imports and settings
  • Prompts you repeatedly to change the notebook name from “Untitled”

The extension running when a new notebook is opened

The benefits of this extension are that it changes the defaults. By default, the Jupyter Notebook has no markdown cells, is unnamed, and has no imports. We know that humans are notoriously bad at changing default settings so why not make the defaults encourage better practices? Think of the Setup extension as a nudge — one that gently pushes you to write better notebooks.

To use this extension:

  1. Install Jupyter Notebook extensions (which you should be using anyway)
  2. Go to GitHub and download the <a href="https://github.com/WillKoehrsen/Data-Analysis/tree/master/setup" target="_blank">setup</a> folder (it has 3 files)
  3. Run pip show jupyter_contrib_nbextensions to find where notebook extensions are installed. On my Windows machine (with anaconda) they are at

C:\users\willk\anaconda3\lib\site-packages\jupyter_contrib_nbextensions

and on my mac (without anaconda) they are at:

/usr/local/lib/python3.6/site-packages/jupyter_contrib_nbextensions

  1. Place the setup folder in nbextensions/ under the above path:

  1. Run jupyter contrib nbextensions install to install the new extension

  2. Run a Jupyter Notebook and enableSetup on the nbextensions tab (if you don’t see this tab, open a notebook and go to edit > nbextensions config)

Enable the Setup extension on the nbextensions tab

Now open a new notebook and you’re good to go! You can change the default template in main.js (see my article on writing a Jupyter Notebook extension for more details on how to write your own). The default template and imports are relatively plain, but you can customize them to whatever you want.

Default template and imports

If you open an old notebook, you won’t get the default template, but you will be prompted to change the name from Untitled every time you run a cell:

The Setup extension will continue prompting until the notebook name is changed from Untitled.

Sometimes, a little bit of persistence is what you need to change your ways.

Parting Thoughts

From now on, let’s strive to create better notebooks. It doesn’t take much extra effort and it pays off greatly as others (and your future self) will be able to learn from your notebooks or use the results to make better decisions. Here are a few simple rules for writing effective notebooks:

  • Name your notebooks. Simple but helpful when you have dozens of files.
  • Add clear yet concise explanations of what your code does, how it works, what are the most important results, and what conclusions were drawn. I use a standard template for notebooks to encourage the habit.
  • Run all your cells in order before sharing a notebook and make sure there are no errors.

The Setup extension will not solve all notebook-related problems, but hopefully, the small nudges will encourage you to adopt better habits. It takes a while to build up best practices, but, once you have them down, they tend to stick. With a little bit of extra effort, we can make sure that the next talk someone gives about notebooks is: “I like effective Jupyter Notebooks.”

#python #data-science

What is GEEK

Buddha Community

Set Your Jupyter Notebook up Right with this Extension

Rodrigo Senra - Jupyter Notebooks

Nosso convidado de hoje é diretor técnico na Work & Co, PhD em Ciências da Computação, já contribuiu com inúmeros projetos open source em Python, ajudou a fundar a Associação Python Brasil e já foi premiado com o Prêmio Dorneles Tremea por contribuições para a comunidade Python Brasil.

#alexandre oliva #anaconda #apache zeppelin #associação python brasil #azure notebooks #beakerx #binder #c++ #closure #colaboratory #donald knuth #fernando pérez #fortran #graphql #guido van rossum #ipython #java #javascript #json #jupyter kenels #jupyter notebooks #jupyterhub #jupyterlab #latex #lisp #literate programming #lua #matlab #perl #cinerdia #prêmio dorneles tremea #python #r #rodrigo senra #scala #spark notebook #tcl #typescript #zope

How to set up Anaconda and Jupyter Notebook the right way

If Anaconda (conda) and Jupyter Notebook (Jupyter Lab) are set up the right way the combination of them can become the perfect team, where you are able to easily switch between Deep Learning conda environments.

Some programs requiring Tensorflow 1.15, others Tensorflow 2.0? No problem! Just switch environments and Tensorflow versions with a simple click.

Also, did you ever install Jupyter Notebook extensions in each conda environment? Do not worry anymore, we are going to install the extensions once, and have them available in each environment!

How are we going to achieve that?

  1. Install Anaconda or Miniconda
  2. Install Jupyter Notebook / Lab in the base environment
  3. Install a new environment
  4. Activate the environment for Jupyter Notebook

#tensorflow #jupyter #jupyter-notebook #anaconda #conda

How to Convert Jupyter Notebooks into PDF

If you’re one of many data scientists looking for a job, you might find yourself working on a data science take-home assignment. Instead of sharing your Jupyter Notebooks, it would be neater if you could convert the notebooks and submit the pdf version. In this blog, I want to share how you can turn Jupyter Notebooks into pdf format in a few lines!

Install nbconvert and LaTeX

nbconvert allows users to convert Notebooks to other formats. You would think after installing nbconvert, and you are good to go…right? If it’s that simple, why would I be writing this post?

After I installed nbconvert, I received an error saying “500: Internal Server Error.” The reason why you see this error is that you will need to install LaTeX or Pandoc as well. I decided to download LaTeX. The good thing about downloading LaTeX is that it makes your analysis look like a research paper, which is very legit.

#template #convert #jupyter-notebook #jupyter #python

Sarai  Thompson

Sarai Thompson

1625284380

Get started with Jupyter Notebook

Jupyter Notebook is an online computational notebook that allows you to combine code, comments, media, and visualizations in interactive documents. It has quickly become one of the most popular online computational notebooks, used by top companies such as Google, Microsoft, and NASA. Today, we’re going to explore Jupyter Notebooks and discuss their benefits and how to get started.

We’ll cover:

#jupyter #python #jupyter-notebook

Arne  Denesik

Arne Denesik

1603263600

Why switch to JupyterLab from jupyter-notebook?

First, let’s talk about both Lab and Notebook separately and then will talk about the differences.

Jupyter Notebook is a web-based interactive computational environment for creating Jupyter notebook documents. It supports several languages like Python (IPython), Julia, R, etc. and is mostly used for data analysis, data visualization, and other interactive, exploratory computing. For beginners in data science, jupyter notebook is more preferred; it only consists of a file browser and a (notebook) editor view, which is easier to use. When you get familiar with it and need more features(which we will talk about later), you can then definitely switch to JupyterLab.

JupyterLab is the next-generation user interface, including notebooks. It has a modular structure, where you can open several notebooks or files (e.g., HTML, Text, Markdowns, etc.) as tabs in the same window. It offers more of an IDE-like experience. JupyterLab uses the same Notebook server and file format as the classic Jupyter Notebook to be fully compatible with the existing notebooks and kernels. The Classic Notebook and Jupyterlab can run side to side on the same computer. One can easily switch between the two interfaces. The interface of both Lab and notebook are similar, except the panel of the file system on the left side in Jupyter lab. You can see that in the images below.

#programming #jupyter #jupyter-notebook #jupyterlab #data-science