from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = "all" # "last" for last statement (like default)
Hack 2: Multicursor in Jupyter Notebook
CTRL + Click at the desired points
Hack 3: List of Variables
%who
Hack 4: List of commands
%history
%history -n # print line numbers for each command
%history -o # print command as well as output
# prints translated history - converts it into valid python commands before execustion
# eg - %history --> get_ipython().run_line_magic('history', '')
%history -n -t
Hack 5: Changing the Theme of a Jupyter Notebook
Follow the below steps:
Install jupyter-themes:
using anaconda conda install -c conda-forge jupyterthemes
using pip pip install jupyterthemes
Check the list of themes – jt - l
Select a theme jt -t chesterish
To restore to default theme – jt -r
Hack 6: Change Cell Width
Install jupyter-themes:
using anaconda conda install -c conda-forge jupyterthemes
using pip pip install jupyterthemes
Change the theme, cell width, cell height jt -t chesterish -cellw 100% lineh 170
Hack 7: Share notebooks via Jupyter nbviewer
Hack 8: Nbconvert to Present your Notebook as Slides
Open a Jupyter notebook
In the toolbar, go to View>>Slideshow
Now each cell will have a “Slide Type” in the top right corner. Select the type of slide depending on your content
Go to command prompt/terminal and type the following command – jupyter nbconvert [file_name] –to slides
Go to the folder where you are running the code and you’ll find, “[file_name.html]”
Open the file and use the keys to change the slides
Hack 9: %prun – Run Python Profiler
Jupyter notebook provides a simple wrapper to run Python Profiler – %prun. A profiler helps you analyze your code so that you can optimize the pain points. It provides you with the number of function calls and the execution time. Other information provided is:
ncalls – number of calls
tottime – The total time spent in the given function (excluding time made in calls to sub-functions)
percall – the quotient of tottime divided by ncalls
cumtime – the total time spent in this and all subfunctions (from invocation till exit)
percall – the quotient of cumtime divided by primitive calls
Hack 10: %%heat – Heatmap over Code
It’s one of the easiest ways to visualize the profiling of your code. By using %%heat, you’ll get an output of your code in the form of a heatmap. This will help you recognize the most time-consuming statements and help you optimize it.
!pip install py-heat-magic
To load the heat as a magic function in your notebook – %load_ext heat
Use %%heat in your notebook cell for which you want to get the heatmap
TL;DR
Contains some hacks for Jupyter Notebook
Link Article
https://www.analyticsvidhya.com/blog/2020/04/10-productive-jupyter-notebook-hacks-tips-tricks/?fbclid=IwAR1IsM5aKUox8YUbWa4ORHEpfeajll8ms_vQCkAWeREJWRPu6xY4oh9cq9A
Key Takeaways
Hack 1: Get multiple outputs in the same cell
Hack 2: Multicursor in Jupyter Notebook
CTRL + Click at the desired points
Hack 3: List of Variables
Hack 4: List of commands
Hack 5: Changing the Theme of a Jupyter Notebook
Follow the below steps:
jupyter-themes
:conda install -c conda-forge jupyterthemes
pip install jupyterthemes
– jt - l
jt -t chesterish
– jt -r
Hack 6: Change Cell Width
jupyter-themes
:conda install -c conda-forge jupyterthemes
pip install jupyterthemes
jt -t chesterish -cellw 100% lineh 170
Hack 7: Share notebooks via Jupyter
nbviewer
Hack 8: Nbconvert to Present your Notebook as Slides
jupyter nbconvert [file_name] –to slides
Hack 9: %prun – Run Python Profiler
Hack 10: %%heat – Heatmap over Code
!pip install py-heat-magic
%load_ext heat
%%heat
in your notebook cell for which you want to get the heatmap