Data Analysis
What is Jupyter Lab
While in command mode (press Esc to activate):
- Shift + Enter run the current cell, select below
- cmd + Enter run selected cells
- Alt + Enter run the current cell, insert below
- cmd + S save and checkpoint
- Enter take you into edit mode
- H show all shortcuts
- Up select cell above
- Down select cell below
- Shift + Up extend selected cells above
- Shift + Down extend selected cells below
- A insert cell above
- B insert cell below
- X cut selected cells
- C copy selected cells
- V paste cells below
- Shift + V paste cells above
- D, D (press the key twice) delete selected cells
- Z undo cell deletion
- S Save and Checkpoint
- Y change the cell type to Code
- M change the cell type to Markdown
- P open the command palette.
While in edit mode (pressEnter to activate)
- Esc take you into command mode
- Tab code completion or indent
- Shift + Tab tooltip
- cmd + ] indent
- cmd + [ dedent
- cmd + A select all
- cmd + Z undo
- cmd + Shift + Z or cmd + Y redo
- cmd + Home go to cell start
- cmd + End go to cell end
- cmd + Left go one word left
- cmd + Right go one word right
- cmd + Shift + P open the command palette
- Down move cursor down
- Up move cursor up
Numpy
Importing/exporting
np.loadtxt('file.txt') | From a text file np.genfromtxt('file.csv',delimiter=',') | From a CSV file np.savetxt('file.txt',arr,delimiter=' ') | Writes to a text file np.savetxt('file.csv',arr,delimiter=',') | Writes to a CSV file
Creating Arrays
np.array([1,2,3]) | One dimensional array np.array([(1,2,3),(4,5,6)]) | Two dimensional array np.zeros(3) | 1D array of length 3 all values 0 np.ones((3,4)) | 3x4 array with all values 1 np.eye(5) | 5x5 array of 0 with 1 on diagonal (Identity matrix) np.linspace(0,100,6) | Array of 6 evenly divided values from 0 to 100 np.arange(0,10,3) | Array of values from 0 to less than 10 with step 3 (eg [0,3,6,9]) np.full((2,3),8) | 2x3 array with all values 8 np.random.rand(4,5) | 4x5 array of random floats between 0–1 np.random.rand(6,7)*100 | 6x7 array of random floats between 0–100 np.random.randint(5,size=(2,3)) | 2x3 array with random ints between 0–4
References