Jupyer Notebook / Lab 유용한 magic 함수들과 ShortCuts(단축키)

2020. 1. 19. 19:13꿀팁 분석 환경 설정/Jupyter Notebook & Lab

728x90
  • Shift + Enter : 현재 셀 실행
  • Ctrl + Enter  : 선택된 셀 모두 실행
  • Alt + Enter  : 현재 셀 실행하고 아래에 셀 삽입
  • Ctrl + S  : 저장

Shortcuts when in edit mode:

  • Esc : command 실행 모드하기 전에 ESC 누르기
  • Tab code completion or indent
  • Shift + Tab : 도움말
  • Ctrl + ] : indent 넣기
  • Ctrl + [ : dedent (indent 빼기?)
  • Ctrl + A : 전체 선택
  • Ctrl + Z : 되돌리기 
  • Ctrl + Shift + Z or Ctrl + Y : redo
  • Ctrl + Home :  맨 위의 셀로 이동
  • Ctrl + End : 맨 아래 셀로 이동
  • Ctrl + Left : 한 단어 앞으로 이동
  • Ctrl + Right :  한 단어 맨 뒤로 이동

ESC 누르고 할 수 있는 것들

  • Scroll up and down your cells with your Up and Down keys.
  • Press A or B to insert a new cell above or below the active cell.
  • M will transform the active cell to a Markdown cell.
  • Y will set the active cell to a code cell.
  • X will cut the selected cell
  • C will copy the selected cell
  • V will paste the cell which is being copied/cut
  • Shift + V paste cells above
  • S will save the notebook
  • F will find/replace
  • O will toggle output
  • D + D (D twice) will delete the active cell.
  • Z will undo cell deletion.
  • For selecting multiple cells at once, hold Shift and press Up or Down
    • Shift + UP UP
    • Shift + Down Down
  • Shift + Space scroll notebook up
  • Space scroll notebook down

다중 셀 처리 방법

  • Shift + M : 아래 있는 셀과 합치기
  • Ctrl + Shift + - : Cell 쪼개기
  • You can also click and Shift + Click in the margin to the left of your cells to select them

shell command 사용하기

앞에 !를 붙이면 됨

!pip install ~~
x = "aa"
!echo $x

Magic Commands

%pastebin magic function to select a range of cells

%pastebin 1-3

## 'http://dpaste.com/2XNJRCR'

 

  • %whos displays the variable type plus some extra info: size, contents, etc.
  • %who_ls only displays the variables name

Working with external files within Jupyter Notebook:

  • %pycat file.py ➡ opens script in the pager
  • %load file.py ➡ inserts the script into a cell
  • %run file.py ➡ runs script
  • %run file.ipynb ➡ runs notebook
  • %notebook filename ➡ exporting the current IPython history to a notebook file

Getting, setting or listing environment variables:

  • %env ➡lists all environment variables
  • %env var ➡ get value for var
  • %env var val➡ set value for var

%system ➡ to use shell (mostly used to get current directory, date, etc)

Autosaving notebook to its checkpoint using %autosave :

Autosaving every 120 seconds (2 minutes)

  • %%HTML ➡ to execute HTML code

  • %%perl ➡ to execute Perl in a subprocess
  • %%javascript or %%js ➡ to execute the block of Javascript code
  • %%python3 ➡ to execute code with python3 in a subprocess
  • %%ruby ➡ to execute Ruby code

Other magic commands:

  • %history ➡ print input history
  • %lsmagic ➡ list currently available magic functions
  • %magic ➡ print information about the magic function system
  • %matplotlib ➡ setting up matplotlib to work interactively
  • %pwd ➡ returns current working directory
  • %quickref ➡ shows a quick reference sheet
  • %time ➡ time execution of a Python statement or expression (it can be used both as a line and cell magic)

https://towardsdatascience.com/optimizing-jupyter-notebook-tips-tricks-and-nbextensions-26d75d502663

 

Optimizing Jupyter Notebook: Tips, Tricks, and nbextensions

Jupyter Notebooks are a web-based and interactive tool that the machine learning and data science community uses a lot. They are used for…

towardsdatascience.com

 

728x90