Create and edit Jupyter notebooks
Creating Jupyter notebooks
Do one of the following:
Right-click the target directory in the Workspace tool window, and select New from the context menu.
Press Alt+Insert
Select Jupyter Notebook.
In the dialog that opens, type a filename.
A notebook document has the *.ipynb extension and is marked with the corresponding icon.
Editing Jupyter notebooks
You can apply various editing actions to one cell or to the entire notebook. Press the Control+A once to select a cell at caret, and press Control+A twice to select all cells in the notebook.
When editing notebook files, mind that DataSpell updates the source code and the preview of the notebook if it has been changed externally.
The editor for Jupyter notebooks has two modes: the edit mode and the command mode. Depending on the mode you can either edit code in notebook cells or use keyboard shortcuts to perform specific actions with cells.
Edit mode
To toggle the edit mode, press Enter or click any cell.
When a cell is in the edit mode, it has a green border on the left and a highlighted line with a caret.
When in the edit mode, you can navigate through all cells line by line using Up/Down keys.
Command mode
Edit cells
A newly created notebook contains one code cell. You can change its type with the cell type selector in the notebook toolbar:
To edit a code cell, just click it.
To edit a Markdown cell, double-click it and start typing. To preview the output, press Shift + Enter.
Working with notebook cells
Add cells
To add a code cell above the selected cell, do one of the following:
In the edit mode, press Alt+Shift+A.
In the command mode, press A.
Select
in the main menu.
To add a code cell below the selected cell, do one of the following:
In the edit mode, press Alt+Shift+B.
In the command mode, press B.
Select
in the main menu.Click in the notebook toolbar.
You can add code or Markdown cells by using the popup between cells:
To add a Markdown cell, go to
in the main menu, and then select either or .
Select cells
To select a cell, click the gutter next to the cell.
To select several cells:
Hold Shift and click the gutter next to cells.
You can select a series of consecutive cells.
In command mode, press Shift and Up/Down keys.
You can execute, copy, merge, and delete the selected cells.
Copy and paste cells
To copy a cell in the command mode, press Control+C, C, or click on the notebook toolbar.
To paste the copied cell below, press Control+V, V, or click .
To paste it above the current cell, press Shift with Control+V/Shift+V.
You can also select the required action from the cell's context menu.
Split and merge cells
To merge a current cell with the cell below, right-click the cell and select
command from the context menu.Similarly, you can merge a cell above the selected cell with the corresponding command.
To merge several cells, select them, and then choose from the main menu.
Alternatively, you can use Find action to run the Merge Selected Cells command.
To split a cell into two cells, set the cursor on the line to break at, then right-click, and select the
from the context menu.
Delete cells
In the command mode, press D, D or Delete.
Click on the notebook editor toolbar.
Right-click the cell and select
from the context menu.
Use code assistance
You can edit code cells with the help of Python code insights, such as syntax highlighting, code completion, and so on.
DataSpell enables Code completion for the names of classes, functions, and variables. Start typing the name of the code construct, and the suggestion list appears.
Intention actions and quick fixes. You can add the missing imports on-the-fly by using the intention actions.
Note that you can add an import statement to the current cell or to the first cell of the notebook.
Navigate through the notebook
You can preview the outline of the Markdown headings in the Structure tool window. To open it, select from the main menu.
Click to navigate from the selected heading in the editor to the corresponding item in the Structure tool window.
Similarly, click to navigate from the selected item in the notebook structure to the corresponding Markdown cell.
Compare notebooks
To compare any two notebooks, select one in the Workspace tool window, right-click it, and select from the context menu (Control+D).
In the file system, select a notebook you want to compare to.
DataSpell shows two notebooks and the comparison results in the diff viewer:
You can modify each of the compared notebooks by using the buttons: and . You can also edit the notebooks directly in the diff viewer. Once the change is applied, DataSpell saves it.