Introduction to Jupyter notebook usage

Welcome to pay attention to my personal station, click to enter

This article is about some usages of jupyter notebook (hereinafter referred to as jupyter). Many programming enthusiasts who are just starting to learn python will choose Anaconda at the beginning, especially Jupyter at the beginning, and will only be exposed to other compilation environments after they are proficient.
Jupyter notebook is an editor that can be edited on the web, which can divide the code into individual modules, and each module can be run separately. Personal feeling is to combine the advantages of file editing code and command line running code. Not only can you save the written code, but you can also view the running results at any time like a console and display them below the code block.

installation method

Jupyter is generally installed along with anaconda (3x is like this, 2x is not expected), after installation, you can see this at the beginning:
insert image description here

How to start jupyter notebook

  • The first method is to find the folder where the suffix file
    needs to be opened , hold it down, and then right-click on the blank space (remember not to select any file before clicking): click the option in the pop-up function box , and then click Input in the box , and you don’t need to worry about it after you press Enter (don’t close this box, just minimize it): Note: Power shell is added only in win10; if it’s win7, click it, the effect is similar, but the style is slightly different different. Next, your browser will automatically open a window, just click on the file you want to open:.ipynbshift
    insert image description here
    在此处打开Power shell窗口jupyter notebookinsert image description here
    在此处打开命令窗口

    insert image description here
  • The second method

First, win+R pops up the run box, enter it cmd, and then a black box will pop up, cd to the folder where the file you need to open is located, and jupyter notebookjust enter.
insert image description here
This method is similar to the previous one, and I personally think the first one is easier to use.

Jupyter various shortcut keys

First create a python3 file, as shown in the figure below:
insert image description here
There will be a menu bar on it, click help and a drop-down box will appear, click Keyboard Shortcutsto view all shortcut keys.
insert image description here
The following is a general introduction to the following commonly used shortcut keys (compared with the official ones, it is definitely not complete, if you want to fully understand, you can check it yourself according to the above method)

  • Execute the current cell and automatically jump to the next cell:Shift Enter
  • Execute the current cell without automatically switching to the next cell after execution:Ctrl-Enter
  • Is the current cell enters edit mode:Enter
  • Exit the edit mode of the current cell:Esc
  • Delete the current cell: double D
  • Add line number to the current cell: single L
  • Add line number to the whole file:shitf L
  • Convert the current cell into a maskdown with a first-level title: single 1
  • Convert the current cell into a maskdown with a secondary title: Single 2
  • Convert the current cell into a maskdown with a three-level title: single 3
  • Add/uncomment one or more lines:Crtl /
  • Undo the deletion of a cell:z
  • Switch between tabs in the browser: Crtl PgUpandCrtl PgDn
  • Quickly jump to the first cell:Crtl Home
  • Quickly jump to the last cell:Crtl End
  • Add a cell above the current cell:A
  • Add a cell below the current cell:B

Import code to jupyter cell

  • Import the local file into the cell:
%load filename.py  # 非当前路径下的需要加上路径

After typing pressshift enter

  • Load code from the network to jupyter
%load http://……  #代码的网址  

run python file

%run filename.py  

some other uses

!python --version  #查看版本
!python myfile.py  #运行文件

get the current path

current_path = %pwd

Plotting with Matplotlib

%matlablib inline

Markdown function

Cell can support Markdown, please refer to my other blog for specific syntax: [Introduction to Markdown Grammar][Markdown]

add directory

  1. Install Jupyter Notebook extensions using Anacondaconda install -c conda-forge jupyter_contrib_nbextensions
    insert image description here
  2. Open Jupyter Notebook and check "Table of Contents(2)" under its (new) Nbextensions tab
    insert image description here
  3. Open a .ipynbfile to see the directory function:
    insert image description here

end

Personally, I think the great thing about jupyter is that it is used as courseware. Lectures will be very convenient, you can demonstrate at any time, and you can add explanations or notes. At the same time, it can also be directly converted into some file formats such as .py, .pdf, .html, .tex, and so on. .mdvery convenient~~

insert image description here

Usually, I seldom use jupyter. In fact, there are many functions and tips. I will write an article to supplement it after I become more proficient in the future. Please look forward to it~~

References: https://blog.csdn.net/tina_ttl/article/details/51031113

This article is also available on my personal website~ There are more experience articles in it, click to enter

Guess you like

Origin blog.csdn.net/weixin_42992706/article/details/89714810