DataSpell 2024.2 Help

Create and edit Jupyter notebooks

Set up your project

  1. Open your workspace.

  2. Install the jupyter package for the selected interpreter.

  3. When all the indexing processes are finished, you are ready to start working with the notebook files.

Creating Jupyter notebooks

  1. 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

  2. Select Jupyter Notebook.

    Adding a new file
  3. In the dialog that opens, type a filename.

A notebook file has the *.ipynb extension and is marked with the corresponding icon Jupyter.

Convert a Python file to a Jupyter notebook

  1. Right-click the file in the Project tool window.

  2. Select Convert to Jupyter Notebook from the context menu.

Convert a Jupyter notebook to a Python file

  1. Right-click the file in the Project tool window.

  2. Select Convert to Python File from the context menu.

Export Jupyter notebooks

You can export Jupyter notebooks to various formats:

  1. Right-click the Jupyter notebook file in the Project tool window.

  2. Select Export Notebook As and then select the format from the list.

    Export a Jupyter notebook file

Edit Jupyter notebooks

You can apply various editing actions to one cell or to the entire notebook. Press the Ctrl+A once to select a cell at the caret and press Ctrl+A twice to select all cells in the notebook.

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 highlighted line with a caret inside the cell.

    A cell in the edit mode
  • When in the edit mode, you can navigate through all cells line-by-line using Up and Down keys.

Command mode

  • To toggle the command mode, press Escape or click the gutter.

  • When in the command mode, you can navigate the notebook cell by cell using Up and Down keys, as well as use keyboard shortcuts to select, copy, paste, and delete cells.

Edit cells

  • A newly created notebook contains one code cell. You can change its type with the cell type selector in the notebook toolbar:

    Select a cell type
  • To edit a code cell, just click it.

  • To edit a Markdown cell, double-click it or press Enter and start typing. To preview the output, press Shift+Enter.

Work with notebook cells

Add cells

  • To add a code cell above the selected cell, do one of the following:

  • 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 Cell | Add Code Cell Below in the main menu.

    • Click in the notebook toolbar.

    Adding a notebook cell
  • Use the popup between cells to add code, Markdown, SQL or AI cells to your notebook:

    Popup between Jupyter notebook cells

Select cells

  • To select a cell, click the gutter next to the cell.

  • To select several cells:

    • Click the gutter next to cells while holding Shift for a series of consecutive cells, or Ctrl for non-consecutive cells.

    • In command mode, hold Shift and press the Up and Down keys.

You can execute, copy, merge, expand, and delete the selected cells.

Copy and paste cells

  • To copy a cell in the command mode, press Ctrl+C, C, or click Copy cell on the notebook toolbar.

  • To paste the copied cell below, press Ctrl+V, V, or click Paste Below Cell.

  • To paste it above the current cell, press Shift with Ctrl+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 the Merge Cell Below 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 Cell | Merge Selected Cells from the main menu.

    Alternatively, you can use Find Action to run the Merge Selected Cells command.

  • To split a cell into two cells, place the caret in the line to break at, then right-click, and select the Split Cell from the context menu.

Expand and collapse cells

  • Click the border in the gutter to expand or collapse a notebook cell.

Expanded notebook cell
Collapsed notebook cell

Delete cells

  • Click Delete Cell Delete Cell on the notebook toolbar.

  • Right-click the cell and select Delete Cell from the context menu.

Add cell tag

You can assign and view tags for each cell right in the notebook editor:

  1. Right-click the cell.

  2. Select Add Cell Tag from the context menu.

  3. Enter the tag and click Confirm.

To remove the tag, right-click it and select Remove Tag.

Use coding assistance

You can edit code cells with the help of Python code insights, such as syntax highlighting and code completion.

  • 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.

    Function completion
    Class variable completion
    Path completion
    Package completion
    DataFrame column name completion
  • Intention actions and quick fixes. You can add the missing imports by using the intention actions.

    Quick-fix for the missing import

    Note that you can add an import statement to the current cell or to the first cell of the notebook.

You can preview the outline of the Markdown headings in the Structure tool window. To open it, select Window | Tool Windows | Structure from the main menu.

Notebook structure
  • Click Navigate with Single click to navigate from the selected heading in the editor to the corresponding item in the Structure tool window.

  • Similarly, click Always select opened element to navigate from the selected item in the notebook structure to the corresponding Markdown cell.

Compare notebooks

  1. To compare any two notebooks, select one in the Workspace tool window, right-click it, and select Compare With from the context menu (Ctrl+D).

  2. In the file system, select a notebook you want to compare to.

  3. DataSpell shows two notebooks and the comparison results in the diff viewer:

    compare two notebooks
  4. You can modify each of the compared notebooks by using the buttons: apply diff change and apply diff change. You can also edit the notebooks directly in the diff viewer. Once the change is applied, DataSpell saves it.

Last modified: 11 October 2024