Ipython Notebook Tutorials

Source: Internet
Author: User
Tags python script jupyter jupyter notebook

Catalogue
* Introduction
* Installation and operation
* Main panel (Notebook Dashboard)
* Editing Interface (Notebook editor)
* Unit (cell)
* Magic function
* Other

First, Introduction

Jupyter Notebook is an open-source Web application that allows users to create and share documents that contain code, equations, visualizations, and text. Its uses include: Data cleansing and transformation, numerical simulation, statistical modeling, data visualization, machine learning, and so on. It has the following advantages:

    • Selectable languages: Supports more than 40 programming languages, including Python, R, Julia, Scala, and more.
    • Share notebooks: You can share them with others using email, Dropbox, GitHub, and Jupyter Notebook Viewer.
    • Interactive output: Code can generate rich interactive output, including HTML, images, videos, latex, and more.
    • Big Data consolidation: Use Big Data framework tools like Apache Spark in Python, R, and Scala programming languages. Supports the use of Pandas, Scikit-learn, Ggplot2, TensorFlow to explore the same data.
Second, installation and operation

Although Jupyter can run multiple programming languages, Python is a prerequisite for installing Jupyter noterbook (Python2.7, or Python3.3 above). There are two ways to install it: Install using Anaconda or use the PIP command. All information about the installation can be read on the website: install Jupyter.

2.1 Installing with Anaconda

For small white, it is highly recommended to install Python and Jupyter using the Anaconda release, which includes Python, Jupyter notebook, and other commonly used scientific computing and data science packages.

First, download the Anaconda. We recommend downloading the latest version of Python 3 for Anaconda. Second, please follow the instructions on the download page to install the downloaded Anaconda version. Finally, the installation is successful!

2.2 Installing using the PIP command

For experienced Python users, you can use Python's Package manager Pip instead of Anaconda to install Jupyter.
If Python 3 is already installed:

python3 -m pip install --upgrade pippython3 -m pip install jupyter
    • 1
    • 2

If Python 2 is already installed:

install --upgrade pippython -m pip install jupyter
    • 1
    • 2

Congratulations, you have successfully installed it!

2.3 Running Jupyter Notebook

After you successfully install Jupyter Notebook, you can open Prompt Jupyter by running the following command in Terminal (mac/linux) or command Notebook (Windows).

jupyter notebook
    • 1

Here's a demonstration of opening Jupyter Notebook in a Windows system:

See the Windows Common CMD command For more information about command prompt.

See Running notebook for more details.

Three, the main panel (Notebook Dashboard)

Open the notebook and you can see the main panel. There are four options for files, Running, Clusters, Conda in the menu bar. The most used is files, where we can complete notebook, renaming, copying, and so on. The specific functions are as follows:

In running, you can see the running notebook, and we can choose to end the running program.

As for clusters, Conda generally do not use, temporarily do not introduce, follow-up supplement.

Iv. Editing Interface (Notebook editor)

A notebook editing interface consists of four main parts: a name, a menu bar, a toolbar, and a unit (cell), as shown in:

4.1 Name

Here, we can modify the name of notebook, directly click on the current name, pop-up dialog to modify:

4.2 Menu Bar

The menu bar has file, Edit, View, Insert, Cell, Kernel, Help and other functions, described below.

4.2.1 File

The button options in file are as follows:

The following table is the specific function:

Options function
New Notebook Create a new Notebook
Open ... Open the main panel in a new page
Make a Copy ... Copy the current notebook to generate a new notebook
Rename ... Notebook renaming
Save and Checkpoint Saves the current notebook state as a checkpoint
Revert to Checkpoint Revert to the previously saved checkpoint
Print Preview Print Preview
Download as Download notebook files to some type of file
Close and Halt Stop running and exit the notebook
4.2.2 Edit

The button options in edit are as follows:

The following table is the specific function:

Options function
Cut Cells Shear Unit
Copy Cells Copy Unit
Paste Cells Above Pastes the copied cells above the current cell
Paste Cells Below Pastes the copied cells below the current cell
Paste Cells & Replace Replaces the current cell as a copied unit
Delete Cells Delete a unit
Undo Delete Cells Recall delete operation
Split Cell Splits the current cell from the mouse position at two cells
Merge Cell Above Merge the current cell and the upper unit
Merge Cell Below Merge the current cell and the lower unit
Move Cell up Move the current unit up one level
Move Cell Down Move the current cell down one level
Edit Notebook Metadata Edit metadata for Notebook
Find and Replace Find replacements that support multiple substitutions: case-sensitive, using JavaScript regular expressions, replacing in selected cells or all cells
4.2.3 View

The button options in view are as follows:

The following table is the specific function:

Options function
Toggle Header Hide/show Jupyter notebook's logo and name
Toggle Toolbar Hide/show Jupyter notebook tool bar
Cell Toolbar Change the unit display style

The features in view allow users to better present their notebook, but have no effect on writing code or implementing functionality.

4.2.4 Insert

Function: Inserts a new cell above/below the current unit.

4.2.5 Cell

Options function
Run Cells Running in-cell code
Run Cells and Select Below Run the in-cell code and move the cursor to the next cell
Run Cells and Insert Below Run the in-cell code and create a new unit below
Run All Run the code inside all the cells
Run All Above Run the code in all the cells above the unit (not included)
Run All Below Run the code in all the cells below the unit (including)
Cell Type Select the nature of the unit content
Current Outputs Hide/Show/scroll/clear the output of the current cell
All Output Hide/Show/scroll/clear the output of all cells
4.2.6 Kernel

[The picture crosses ... (5.png-36664e-1514169774199-0)]

Options function
Interrupt Interrupt-to-kernel connection (equivalent to ctrl-c)
Restart Rebooting the kernel
Restart & Clear Output Reboot the kernel and empty the existing output
Restart & Run All Reboot the kernel and rerun all code in Notebook
Reconnect Reconnect to the kernel
Change kernel Switching cores
4.2.7 Help

Options function
User Interface Tour User Guide, very good features, to bring you a comprehensive understanding of notebook
Keyboard shortcuts Shortcut keys Daquan
Notebook Help Notebook User Guide
Markdown Markdown User Guide
Python...pandas Various usage guides
About Some information about the Jupyter notebook
4.3 Tool strips

The features in the toolbar are basically available in the menu, so that you can do it more quickly and put some of the usual buttons out of the way. Is the explanation of each button.

4.4 Unit (cell)

In the cell we can edit text, write code, draw pictures, and so on. The detailed contents of the unit are described in section fifth.

Five, Unit (cell) 5.1 Two modes and shortcut keys

For units in notebook, there are two modes: Command mode and edit mode, which we can do differently in different modes.

For example, under edit mode, a pencil icon appears in the upper-right corner, the left border of the unit is green, the ESC key or the running cell (ctrl-enter) switches back to command mode.

In command mode, the pencil icon disappears, the left border line of the unit is blue, press ENTER, or double-click the cell to edit the state.

5.1.1 shortcut keys in command mode

5.1.2 shortcut keys in edit mode

Be careful not to memorize, use the process of what you need to check, more use can be remembered.

Four functions of the 5.2 cell

Cell has four functions: Code, Markdown, Raw Nbconvert, Heading, these four functions can switch each other. Code is used for writing codes, markdown for text editing, text or code in Raw Nbconvert, and so on, heading is used to set the title, which is already included in the markdown. The four functions can be toggled using shortcut keys or toolbars.

Code is used to write codes, and the three types of prompts and meanings are as follows:

prompt meaning
In[] Program not running
In[num] After the program runs
In[*] Program is running

Markdown is used to edit text and gives common markdown usage:

Other non-common usage can be reviewed when needed.

Six, Magic function

Using the Magic function, you can simply implement some of the functions that Python needs to be cumbersome to implement.

%: Line Magic function, only valid for our code.
The%%:cell magic function, which takes effect throughout the cell, must be placed in the first row of the cell.
%lsmagic: List all the Magic functions
%magic view descriptions of each magic function
After that, you can see the description of the function by adding the name of the Magic function

Examples of some common magic functions:

Magic Function function
%%writefile Calling external python script
%run Calling external python script
%timeit test Execution time of a single-line statement
%%timeit tests the execution time of code in the entire cell
% matplotlib inline Displays the graphics generated by the Matplotlib package
%%writefile write file
%pdb Debugger
%pwd View current working directory
%ls to view a list of directory files
%reset clears all variables
%who View the names of all global variables, and only return a list of variables of that type if given a type parameter
%whos displays all global variable names, types, values/information
%xmode Plain is set to show simple exception information when an exception occurs
%xmode Verbose set to show detailed exception information when an exception occurs
%debug bug Debug, enter quit debugging
%env List all environment variables

Note that these commands are applicable in Python kernel, and other kernel do not necessarily apply

Vii. Other

(1) Press the TAB key to view the prompt information or complete the command

(2) Before a library, method, or variable is added, you can get a quick syntax description for it

(3) Use a semicolon to block the result output of the line function

Ipython Notebook Tutorials

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.