未加星标

27 Jupyter Notebook tips, tricks and shortcuts

字体大小 | |
[开发(python) 所属分类 开发(python) | 发布者 店小二05 | 时间 2016 | 作者 红领巾 ] 0人收藏点击收藏

This post originally appeared on Alex Rogozhnikov’s blog, ‘Brilliantly Wrong’ . Alex has graciously let us republish his post here.

Jupyter Notebook

Jupyter notebook, formerly known as the Ipython notebook, is a flexible tool that helps you create readable analyses, as you can keep code, images, comments, formulae and plots together.

Jupyter is quite extensible, supports many programming languages and is easily hosted on your computer or on almost any server ― you only need to have ssh or http access. Best of all, it’s completely free.


27 Jupyter Notebook tips, tricks and shortcuts

The Jupyter interface.

By default, Jupyter works with Python kernels - hence its historical name as the IPython notebook. Jupyter notebook is produced by the Jupyter project - the name Jupyter is an indirect acronyum of the three core languages it was designed for: JU lia, PYT hon, and R and is inspired by the planet Jupiter. We’re going to show you 27 tips and tricks to make your life working with Jupyter easier.

1. Keyboard Shortcuts

As any power user knows, keyboard shortcuts will save you lots of time. Jupyter stores a list of keybord shortcuts under the menu at the top: Help > Keyboard Shortcuts . It’s worth checking this each time you update Jupyter, as more shortcuts are added all the time.

Another way to access keyboard shortcuts, and a handy way to learn them is to use the command palette: Cmd + Shift + P (or Ctrl + Shift + P on linux and windows). This dialog box helps you run any command by name - useful if you don’t know the keyboard shortcut for an action or if what you want to do does not have a keyboard shortcut. The functionality is similar to Spotlight search on a Mac, and once you start using it you’ll wonder how you lived without it!


27 Jupyter Notebook tips, tricks and shortcuts
27 Jupyter Notebook tips, tricks and shortcuts

The command palette.

Some of my favorites:

Esc + F Find and replace on your code but not the outputs. Esc + O Toggle cell output. Select Multiple Cells:
- Shift + J or Shift + Down selects the next sell in a downwards direction. You can also select sells in an upwards direction by using Shift + K or Shift + Up . Once cells are selected, you can then delete / copy / cut / paste / run them as a batch. This is helpful when you need to move parts of a notebook. You can also use Shift + M to merge multiple cells.
27 Jupyter Notebook tips, tricks and shortcuts
27 Jupyter Notebook tips, tricks and shortcuts

Merging multiple cells.

2. Pretty Display of Variables

The first part of this is pretty widely known. By finishing a Jupyter cell with the name of a variable or unassigned output of a statement, Jupyter will display that variable without the need for a print statement. This is especially useful when dealing with Pandas DataFrames, as the output is neatly formatted into a table.

What is known less, is that you can alter a modify the ast_note_interactivity kernel option to make jupyter do this for any variable or statement on it’s own line, so you can see the value of multiple statements at once.

In[1]:

from IPython.core.interactiveshell import InteractiveShell InteractiveShell.ast_node_interactivity = "all"

In[2]:

from pydataset import data quakes = data('quakes') quakes.head() quakes.tail()

Out[2]: lat long depth mag stations 1 -20.42 181.62 562 4.8 41 2 -20.62 181.03 650 4.2 15 3 -26.00 184.10 42 5.4 43 4 -17.97 181.66 626 4.1 19 5 -20.42 181.96 649 4.0 11 Out[2]: lat long depth mag stations 996 -25.93 179.54 470 4.4 22 997 -12.28 167.06 248 4.7 35 998 -20.13 184.20 244 4.5 34 999 -17.40 187.80 40 4.5 14 1000 -21.59 170.56 165 6.0 119

If you want to set this behaviour for all instances of Jupyter (Notebook and Console), simply create a file ~/.ipython/profile_default/ipython_config.py with the lines below.

c = get_config() # Run all nodes interactively c.InteractiveShell.ast_node_interactivity = "all" 3. Easy links to documentation

Inside the Help menu you’ll find handy links to the online documentation for common libraries including NumPy, Pandas, SciPy and Matplotlib.

Don’t forget also that by prepending a library, method or variable with ? , you can access the Docstring for quick reference on syntax.

In[3]:

?str.replace()

Docstring: S.replace(old, new[, count]) -> str Return a copy of S with all occurrences of substring old replaced by new. If the optional argument count is given, only the first count occurrences are replaced. Type: method_descriptor 4. Plotting in notebooks

There are many options for generating plots in your notebooks.

- matplotlib (the de-facto standard), activate

本文开发(python)相关术语:python基础教程 python多线程 web开发工程师 软件开发工程师 软件开发流程

主题: LinuxWindowsPython
分页:12
转载请注明
本文标题:27 Jupyter Notebook tips, tricks and shortcuts
本站链接:http://www.codesec.net/view/482243.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 开发(python) | 评论(0) | 阅读(44)