4 Simple Yet Useful Jupyter Features You Should Know
Improve the productivity of your notebooking
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.
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 %who
or %whos
, as shown below, with the latter showing more details of the 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.
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.
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.
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.
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.
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.
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.