Hướng dẫn how do you add a new cell in python? - làm thế nào để bạn thêm một ô mới trong python?

Dưới đây là một số phím tắt và đoạn văn bản mà tôi đã chia sẻ với những người khác trong các phiên lập trình cặp đã được đón nhận. Họ đã tiết kiệm cho tôi vô số lập trình và hy vọng của tôi là bạn sẽ có thể bắt đầu sử dụng một số kỹ thuật này để trở thành một lập trình viên Python hiệu quả hơn.

Các phím tắt bàn phím

Dành vài phút để tìm hiểu các phím tắt bàn phím Jupyter nhất định đã giúp tôi trở thành một nhà phát triển Python hiệu quả hơn. Dưới đây là các phím tắt mà tôi đã thấy hữu ích nhất.

Lưu ý các phím tắt này dành cho Jupyter phiên bản 4.1.0 và Mac OSX. Đối với hầu hết các phím tắt bên dưới, bạn có thể thay thế cmd cho ctrl cho Windows hoặc Linux. Hoặc, bạn có thể sử dụng phím tắt H trong Windows hoặc Linux để xác nhận các phím tắt bàn phím phù hợp cho các hệ điều hành đó. these keyboard shortcuts are for Jupyter version 4.1.0 and Mac OSX. For most shortcuts below, you can replace cmd for ctrl for Windows or Linux. Or, you can use the H keyboard shortcut in Windows or Linux to confirm the appropriate keyboard shortcuts for those operating systems.

Thực hành Notebook Jupyter

Tôi đã tạo ra sổ ghi chép Jupyter này trên repo GitHub của tôi mà bạn có thể tải xuống và sử dụng để thực hành các phím tắt này.

Chế độ lệnh so với chế độ chỉnh sửa

Nhưng trước tiên, một cái gì đó là chìa khóa để nhận thức: Jupyter Notebooks có hai chế độ đầu vào bàn phím khác nhau:

  1. Chế độ lệnh - Liên kết bàn phím với các hành động cấp độ máy tính xách tay. Được biểu thị bằng đường viền tế bào màu xám với lề trái màu xanh. - binds the keyboard to notebook level actions. Indicated by a grey cell border with a blue left margin.
  2. Chế độ chỉnh sửa - Khi bạn gõ vào một ô. Được biểu thị bằng đường viền tế bào màu xanh lá cây - when you’re typing in a cell. Indicated by a green cell border

Chế độ lệnh

  • shift + enter Chạy ô, chọn bên dưới
  • ctrl + enter Run Cell
  • option + enter Tế bào chạy, chèn bên dưới
  • from __future__ import division
    
    import numpy as np
    
    import pandas as pd
    
    from pandas import Series, DataFrame
    
    from numpy.random import randn
    
    from scipy import stats
    
    import matplotlib as mpl
    import matplotlib.pyplot as plt
    import seaborn as sns
    sns.set_style('whitegrid')
    
    %matplotlib inline
    
    import math
    
    from sklearn.linear_model import LogisticRegression
    from sklearn.linear_model import LinearRegression
    from sklearn.cross_validation import train_test_split
    
    from sklearn import metrics
    
    import statsmodels.api as sm
    
    from pprint import pprint
    
    1 chèn ô ở trên
  • from __future__ import division
    
    import numpy as np
    
    import pandas as pd
    
    from pandas import Series, DataFrame
    
    from numpy.random import randn
    
    from scipy import stats
    
    import matplotlib as mpl
    import matplotlib.pyplot as plt
    import seaborn as sns
    sns.set_style('whitegrid')
    
    %matplotlib inline
    
    import math
    
    from sklearn.linear_model import LogisticRegression
    from sklearn.linear_model import LinearRegression
    from sklearn.cross_validation import train_test_split
    
    from sklearn import metrics
    
    import statsmodels.api as sm
    
    from pprint import pprint
    
    2 Chèn ô bên dưới
  • from __future__ import division
    
    import numpy as np
    
    import pandas as pd
    
    from pandas import Series, DataFrame
    
    from numpy.random import randn
    
    from scipy import stats
    
    import matplotlib as mpl
    import matplotlib.pyplot as plt
    import seaborn as sns
    sns.set_style('whitegrid')
    
    %matplotlib inline
    
    import math
    
    from sklearn.linear_model import LogisticRegression
    from sklearn.linear_model import LinearRegression
    from sklearn.cross_validation import train_test_split
    
    from sklearn import metrics
    
    import statsmodels.api as sm
    
    from pprint import pprint
    
    3 Sao chép ô
  • from __future__ import division
    
    import numpy as np
    
    import pandas as pd
    
    from pandas import Series, DataFrame
    
    from numpy.random import randn
    
    from scipy import stats
    
    import matplotlib as mpl
    import matplotlib.pyplot as plt
    import seaborn as sns
    sns.set_style('whitegrid')
    
    %matplotlib inline
    
    import math
    
    from sklearn.linear_model import LogisticRegression
    from sklearn.linear_model import LinearRegression
    from sklearn.cross_validation import train_test_split
    
    from sklearn import metrics
    
    import statsmodels.api as sm
    
    from pprint import pprint
    
    4 Tế bào dán
  • from __future__ import division
    
    import numpy as np
    
    import pandas as pd
    
    from pandas import Series, DataFrame
    
    from numpy.random import randn
    
    from scipy import stats
    
    import matplotlib as mpl
    import matplotlib.pyplot as plt
    import seaborn as sns
    sns.set_style('whitegrid')
    
    %matplotlib inline
    
    import math
    
    from sklearn.linear_model import LogisticRegression
    from sklearn.linear_model import LinearRegression
    from sklearn.cross_validation import train_test_split
    
    from sklearn import metrics
    
    import statsmodels.api as sm
    
    from pprint import pprint
    
    5,
    from __future__ import division
    
    import numpy as np
    
    import pandas as pd
    
    from pandas import Series, DataFrame
    
    from numpy.random import randn
    
    from scipy import stats
    
    import matplotlib as mpl
    import matplotlib.pyplot as plt
    import seaborn as sns
    sns.set_style('whitegrid')
    
    %matplotlib inline
    
    import math
    
    from sklearn.linear_model import LogisticRegression
    from sklearn.linear_model import LinearRegression
    from sklearn.cross_validation import train_test_split
    
    from sklearn import metrics
    
    import statsmodels.api as sm
    
    from pprint import pprint
    
    5 Xóa ô đã chọn
  • shift +
    from __future__ import division
    
    import numpy as np
    
    import pandas as pd
    
    from pandas import Series, DataFrame
    
    from numpy.random import randn
    
    from scipy import stats
    
    import matplotlib as mpl
    import matplotlib.pyplot as plt
    import seaborn as sns
    sns.set_style('whitegrid')
    
    %matplotlib inline
    
    import math
    
    from sklearn.linear_model import LogisticRegression
    from sklearn.linear_model import LinearRegression
    from sklearn.cross_validation import train_test_split
    
    from sklearn import metrics
    
    import statsmodels.api as sm
    
    from pprint import pprint
    
    8 hợp nhất các ô được chọn hoặc ô hiện tại có ô bên dưới nếu chỉ có một ô được chọn
  • from __future__ import division
    
    import numpy as np
    
    import pandas as pd
    
    from pandas import Series, DataFrame
    
    from numpy.random import randn
    
    from scipy import stats
    
    import matplotlib as mpl
    import matplotlib.pyplot as plt
    import seaborn as sns
    sns.set_style('whitegrid')
    
    %matplotlib inline
    
    import math
    
    from sklearn.linear_model import LogisticRegression
    from sklearn.linear_model import LinearRegression
    from sklearn.cross_validation import train_test_split
    
    from sklearn import metrics
    
    import statsmodels.api as sm
    
    from pprint import pprint
    
    9,
    from __future__ import division
    
    import numpy as np
    
    import pandas as pd
    
    from pandas import Series, DataFrame
    
    from numpy.random import randn
    
    from scipy import stats
    
    import matplotlib as mpl
    import matplotlib.pyplot as plt
    import seaborn as sns
    sns.set_style('whitegrid')
    
    %matplotlib inline
    
    import math
    
    from sklearn.linear_model import LogisticRegression
    from sklearn.linear_model import LinearRegression
    from sklearn.cross_validation import train_test_split
    
    from sklearn import metrics
    
    import statsmodels.api as sm
    
    from pprint import pprint
    
    9 Hạt nhân ngắt
  • cmd1, cmd1 Khởi động lại kernel (với hộp thoại)
  • cmd3 Thay đổi ô thành chế độ cmd4
  • from __future__ import division
    
    import numpy as np
    
    import pandas as pd
    
    from pandas import Series, DataFrame
    
    from numpy.random import randn
    
    from scipy import stats
    
    import matplotlib as mpl
    import matplotlib.pyplot as plt
    import seaborn as sns
    sns.set_style('whitegrid')
    
    %matplotlib inline
    
    import math
    
    from sklearn.linear_model import LogisticRegression
    from sklearn.linear_model import LinearRegression
    from sklearn.cross_validation import train_test_split
    
    from sklearn import metrics
    
    import statsmodels.api as sm
    
    from pprint import pprint
    
    8 Thay đổi ô thành chế độ cmd6 (tốt cho tài liệu)

Chế độ chỉnh sửa

  • cmd + cmd8 để chỉnh sửa đa cursor
  • option + ctrl0 để chỉnh sửa cột
  • cmd + ctrl2 Chuyển đổi các dòng bình luận
  • ctrl3 Hoàn thành mã hoặc thụt
  • shift + ctrl3 Tooltip
  • ctrl + shift + ctrl8 Tế bào phân chia

Bảng màu chỉ huy

cmd + shift + H1

Muốn truy cập nhanh vào tất cả các lệnh trong máy tính xách tay Jupyter? Mở bảng lệnh với cmd + shift + H1 và bạn sẽ nhanh chóng có thể tìm kiếm tất cả các lệnh!

Hướng dẫn how do you add a new cell in python? - làm thế nào để bạn thêm một ô mới trong python?

Xem tất cả các phím tắt

H (ở chế độ lệnh)

Quên cái phím tắt đó là gì? Nhập H trong chế độ lệnh cho danh sách tất cả các phím tắt có sẵn.

Hướng dẫn how do you add a new cell in python? - làm thế nào để bạn thêm một ô mới trong python?

Đoạn trích văn bản

Đoạn trích văn bản cho phép tôi tiết kiệm thời gian gõ và giữ mọi thứ nhất quán.

Đối với các đoạn trích văn bản của tôi, tôi chỉ sử dụng Textexpander, chỉ là Mac OSX. Tuy nhiên, đối với Windows, tôi đã sử dụng Phraseexpress trong quá khứ cũng hoạt động tốt.

Nhập khẩu nhanh cho tất cả các gói yêu thích của bạn

Liên tục nhập cùng một gói và/hoặc quên gói mà bạn luôn sử dụng được đặt tên là gì? Tôi muốn lưu trữ nhập khẩu mặc định của mình trong một đoạn trích như sau. Tôi đã khuyên bạn nên tạo một đoạn trích tương tự và điều chỉnh nó theo sở thích của bạn.

H7 trở thành:

Làm cho chức năng viết và tài liệu ít đau đớn hơn

Tôi muốn nhắc nhở bản thân viết một chức năng DocString mỗi khi tôi viết một hàm bằng cách sử dụng đoạn trích sau.

H8 trở thành:

Điều gì tạo ra một tế bào mới trong Python?

Bạn có thể sử dụng các công cụ menu hoặc phím tắt để tạo các ô mới.Mặc dù loại ô mặc định cho các ô mới là mã, bạn có thể thay đổi loại ô của bất kỳ ô hiện tại nào bằng cách nhấp vào ô và chọn loại ô mới (ví dụ: Markdown) trong menu loại ô trong thanh công cụ.use either the Menu tools or Keyboard Shortcuts to create new cells. While the default cell type for new cells is Code, you can change the cell type of any existing cell by clicking in the cell and selecting a new cell type (e.g. Markdown ) in the cell type menu in the toolbar.

Làm cách nào để tạo một ô mới?

Chèn ô nhấp chuột phải vào ô trên mà bạn muốn chèn một ô mới.Chọn Chèn, và sau đó chọn các ô và chuyển xuống.Right-click the cell above which you want to insert a new cell. Select Insert, and then select Cells & Shift Down.

Làm cách nào để thêm một ô trong Jupyter?

Các phím tắt trong cả hai chế độ: Shift + Enter Chạy ô hiện tại, chọn bên dưới.Ctrl + nhập các ô đã chọn.Alt + Nhập chạy ô hiện tại, chèn bên dưới.Alt + Enter run the current cell, insert below.

Một tế bào Markdown trong Python là gì?

Tế bào Markdown Hiển thị văn bản có thể được định dạng bằng ngôn ngữ Markdown.Để nhập một văn bản không nên được coi là mã bằng máy chủ Notebook, trước tiên, nó phải được chuyển đổi dưới dạng ô đánh dấu từ menu ô hoặc bằng cách sử dụng phím tắt M trong khi ở chế độ lệnh.displays text which can be formatted using markdown language. In order to enter a text which should not be treated as code by Notebook server, it must be first converted as markdown cell either from cell menu or by using keyboard shortcut M while in command mode.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from __future__ import division

import numpy as np

import pandas as pd

from pandas import Series, DataFrame

from numpy.random import randn

from scipy import stats

import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_style('whitegrid')

%matplotlib inline

import math

from sklearn.linear_model import LogisticRegression
from sklearn.linear_model import LinearRegression
from sklearn.cross_validation import train_test_split

from sklearn import metrics

import statsmodels.api as sm

from pprint import pprint