Jupyter notebook Tips and Tricks

Prerequisite: Getting started with Jupyter Notebook

Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. What makes data analysis in Python more efficient and productive is Jupyter notebook or formerly known as the IPython notebook.

In this post, we are going to discuss some nice features of the Jupyter notebook which increases the productivity and efficiency of the data analyst. The Jupyter notebook extends the console-based approach to interactive computing in a qualitatively new direction, providing a web-based application suitable for capturing the whole computation process: developing, documenting, and executing code, as well as communicating the results. In a nutshell, it is a complete package.



Let’s see some features of the Jupyter notebook which comes very handy while doing data analysis.

%%timeit and %%time :

It’s not an uncommon thing for a data scientist that while doing data analysis, they have more than one solutions for the given problem. They want to choose the best approach which completes the task in the minimum amount of time. Jupyter notebook provides a very efficient way to check the running time of a particular block of code.

we can use the %%time command to check the running time of a particular cell. For instance, let’s see the time takes to execute the code mentioned below.

filter_none

edit
close

play_arrow

link
brightness_4
code

# For capturing the execution time
%%time 
  
# Find the squares of a number in the
# range from 0 to 14
for x in range(15):
    square = x**2
    print(square)

chevron_right


Output :

We can also use the command %%timeit to run the given snippet of code over some number of times to find the average run time for that piece of code.

Commenting/Uncommenting a block of code :

While working with codes, we often add new lines of code and comment out the old pieces of code for improving the performance or to debug it. Jupyter notebook provides a very efficient way to achieve the same.

To comment out a block of code –

First, we need to select all those lines which we want to comment out.

Next, on a Windows computer, we need to press the ctrl + / key combination to comment out the highlighted portion of the code.

This does save a lot of time for the data analyst.

To Uncomment a commented block of code –

The steps are same for uncommenting a block of code. First, we highlight the commented region of the code.

Next, on a Windows computer, we need to press the ctrl + / key combination to comment out the highlighted portion of the code.



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

1


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.