[Data Analysis - Basic Introduction to NumPy②] Jupyter Notebook Installation and Use

foreword

Hello everyone, I am Xiangyang Huahuahua. This issue brings you the installation and use of Jupyter Notebook. The author's
[Python Data Analysis] column is being updated hotly. If this article is helpful to you, please like + comment + bookmark!

Daily golden sentence sharing: It doesn’t matter whether you are slow or small, as long as you walk forward. 』—— Anonymous "Netease Cloud Music Review" .

Without further ado, let's get into the text.

1. Installation and use of Jupyter Notebook

In the previous article, we installed Anaconda. In this issue, we will learn to use Jupyter Notebook.

1.1 Three ways to open Jupyter Notebook

There are three ways to open Jupyter Notebook... It should be noted that none of the three ways can close the command prompt window or the Power Shell window. If closed, the Jupyter Notebook service will be terminated.

1. Click Anaconda Prompt to open

Select Anaconda in the Start menu, then click Anaconda Prompt.

Anaconda Prompt

Then enter in the command line jupyter notebookto open Jupyter Notebook. At this time, Jupyter Notebook opens the user directory of the C drive.


The Web page of Jupyter Notebook, which is our operation page in the future, is as follows.

If you don't want to use it under the C drive, you can switch the drive letter first, and then enter jupyter notebook.

First, we press to ctrl + cend the Jupyter Notebook process. If it doesn’t work once, press it a few more times to close the process directly, or you can X(fork) the web page to close it. There is no difference.


Then, we switch the drive letter and open Jupyter Notebook.


Opened successfully.

2. Click to open Jupyter Notebook

We click on the Anaconda directory on the start menu, and then directly click on Jupyter Notebook.

This way of opening opens the user directory under the C drive, which is also the working directory of Jupyter Notebook. I think it 这可能不是很符合一部分人的操作习惯is the C drive after all.

3. Use Powershell to open

Opening with Powershell is a more convenient way, which allows us to quickly open Jupyter Notebook in any directory.

Suppose I am going to open Jupyter Notebook in the following directory.


Press shift + right mouse button and select Open power shell window here.


Then we enter jupyter notebookto open Jupyter Notebook in this directory.

1.2 Two keyboard input modes of Jupyter Notebook

Jupyter Notebook has two keyboard input modes... and shortcut keys are case insensitive.

1. Edit mode

When the frame cell is green, it is in edit mode. In editing mode, we mainly remember the shortcut keys for code completion, code hints and running units.

hot key effect
Tab code completion or indentation
Shift + Tab View function parameters, the cursor should be in parentheses
Shift + Enter Run this unit, select the next unit
Ctrl + Enter run this unit
Alt + Enter Run this cell and insert a cell below
Esc, click ln [ ] in front of the input box exit edit mode

2. Command mode

When the input box is blue, it is in command mode. We mainly remember cell additions and deletions and cell state transitions.

hot key effect
y Cell enters code mode
m Cell enters markdown format
A Insert new cell above
B insert new cell below
DD delete selected cells
enter enter edit mode

In addition, there are three shortcut keys for running code mode, which are the same as those in edit mode, and will not be listed here.

Two, Jupyter Notebook magic command

There are many magic commands in Jupyter Notebook...

2.1 View help documentation

usage effect
? View descriptions of variables, functions, etc.
?? View a more detailed description

See the code sample below:

len?


Define a function below:

def get_one():
    """
    return the number 1
    """
    return 1

If it is a question mark:

get_one?

Then:

if it is two question marks:

get_one??

So:

It can be seen that the description given by the two question marks is more detailed. After all, there is one more question mark.

2.2 Magic commands

Magic commands basically start with % and are used to implement...

magic order effect
%run After running, import the custom file. After running, the functions, classes, etc. in the file can be used directly
%timeit Statistical running time, generally time-consuming
%time Statistical running time, generally takes a long time
%who View all variable and function names for the current session
%whos Show variable type and value
%who_ls Display variable and function names as a list
pip install for installing packages
lsmagic View all magic commands
? View the help documentation for magic commands

There is an existing file named test.py, which contains the following content:

def display():
   """
   show the number
   """
   print('hello')
def add(x,y):
    return x+y
display()

The following demonstrates the use of magic commands, because the code is relatively short, so it is displayed directly in the form of pictures.


epilogue

This is the end of the content shared with you in this issue! I hope you can gain something after reading the full text. If you have any questions in the article, please add my personal WXonline Q&A at the end of the article, and I will do my best to help you.

Previous articles & related guides

[Data Analysis - Basic Introduction to NumPy①] Anaconda installation and use

Guess you like

Origin blog.csdn.net/qq_62592360/article/details/131500730