avatarYong Cui

Summary

This article discusses four useful features of the Jupyter Notebook that can improve productivity for data scientists.

Abstract

The Jupyter Notebook is a powerful tool for data scientists, allowing them to visualize data and process datasets. This article highlights four features that can enhance the user's experience and productivity. The first feature is running commands in cells by prefixing an exclamation mark before the command. The second feature is checking active variables using the magic methods %who or %whos. The third feature is API lookups, which can help users remember functions or attributes they want to use. The fourth feature is changing the default output mode to display multiple items or the last expression or assignment. These features can be beneficial for data scientists working with large datasets and multiple variables.

Bullet points

  • Running commands in cells by prefixing an exclamation mark before the command
  • Checking active variables using the magic methods %who or %whos
  • API lookups to help users remember functions or attributes they want to use
  • Changing the default output mode to display multiple items or the last expression or assignment

4 Simple Yet Useful Jupyter Features You Should Know

Improve the productivity of your notebooking

Photo by Dan Dimmock on Unsplash

The Jupyter Notebook is a very handy coding tool for data scientists. It allows us to visualize data in the form of text and images while we’re moving forward with the processing and analysis of our datasets. After learning the basic operations with Notebook, we may want to try something more useful that can help improve our Notebook experience and work productivity. In this article, I’d like to share some features that address some particular needs in our data science work.

1. Run Commands

To run commands in cells, we can simply prefix an exclamation mark before the command.

Commands Running in Notebooks

One common question associated with running commands is how we interact with prompts, such as installation confirmation (yes or no), during some execution. The trick is to append the yes flag (-y) to the command, like below.

!pip uninstall seaborn -y

2. Check Active Variables

When we work with lots of data, we may have created many intermediate variables in our workspace. To get to know the current pool of these variables, we can use the magic method %whoor %whos, as shown below, with the latter showing more details of the variables.

Check Variables

To make this command more interesting, we can specify the data type of the variables to create a shorter list. For instance, the command below only shows the variables with a type of string.

Check Variables of Particular Types

3. API Lookups

We don’t always remember the functions or attributes that we want to use. However, we do have some impressions about them, after all, we may have used them from time to time before. In this case, we can list all related methods that may remind us.

API Lookups

The above screenshot shows you we want to get the list of supported plots that are available in the seaborn package. The trick is simply to use the wildcard in the string with a prefix of the question mark. Once you know what method you’re about to use, to check the calling signature, you can use the question mark with the specific function name, as shown below.

Specific Function Details

The output is similar to what you can get with the help function, like below.

help(seaborn.rugplot)

4. Change the Default Output Mode

By default, each cell only prints the last expression after executing the entire cell, as shown below.

Display of the Last Expression

However, chances are that we want to display more items, such as all the expressions in the cell. In this case, we can change the default setting that allows the output of multiple items.

Output Multiple Items

By assessing the source code of the interactivity mode, we can have other options. For instance, the below update outputs the last expression or last assignment. As you know, an assignment normally doesn’t output anything.

Output Expression or Assignment’s Value

If you’re interested in trying other options, here’s the source code that includes the possible options. Note that the default value is “last_expr”, with which you can set the Notebook to its original state.

Conclusions

In this article, we reviewed four simple yet useful Notebook features that you can try in your own data science work. There are many features that are worth noting too, such as Notebook extensions, widgets, and many other magic commands. We can explore them in future articles.

Data Science
Technology
Machine Learning
Programming
Recommended from ReadMedium