Create and edit Jupyter notebooks
note
Make sure that you have conda installed.
Go to File | New Project.
Select a Jupyter project template.
Select the project location. Click
in the Location field and specify the directory for your project. The project name will be automatically derived from the folder name in the specified path.
Select Create Git repository to put the project under Git version control.
Select Create a simple Jupyter notebook if you want PyCharm to add the
sample.ipynb
file to your project. This file contains a sample Jupyter Notebook and can help you get acquainted with the notebook editor UI and other features.Click Create.
To open an existing .ipynb file, follow the same steps as for the files of the other types. If needed, you can create a notebook file.
Do one of the following:
Right-click the target directory in the Project tool window and select New from the context menu.
Press
Select Jupyter Notebook.
In the dialog that opens, type a filename.
A notebook file has the *.ipynb extension and is marked with the corresponding icon .
Right-click the file in the Project tool window.
Select Convert to Jupyter Notebook from the context menu.
Right-click the file in the Project tool window.
Select Convert to Python File from the context menu.
You can export Jupyter notebooks to various formats:
Right-click the Jupyter notebook file in the Project tool window.
Select Export Notebook As and then select the format from the list.
You can apply various editing actions to one cell or to the entire notebook. Press the once to select a cell at the caret and press twice to select all cells in the notebook.
note
PyCharm 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.
To toggle the edit mode, press or click any cell.
When a cell is in the edit mode, it has a highlighted line with a caret inside the cell.
When in the edit mode, you can navigate through all cells line-by-line using and keys.
A newly created notebook contains one code cell. To change its type, right-click the cell and select Convert Cell to Markdown or Convert Cell to SQL from the context menu.
To edit a code cell, just click it.
To edit a Markdown cell, double-click it or press and start typing. To preview the output, press .
After you select the part of the text in the Markdown cell, the toolbar appears.
You can use it to apply the following formatting options:
Item
Icon
Shortcut
Description
Text style
Click the dropdown to change text formatting to various heading levels.
Bold text
Makes the selected text bold (
**text**
).Italic text
Makes the selected text italic (
_text_
).Strike through
Strikes through the selected text. (
~~text~~
).Code
Formats text as inline code.
Create link
Adds a hyperlink.
Unordered list
Creates an unordered list.
To add a code cell above the selected cell, do one of the following:
In the edit mode, press .
In the command mode, press .
To add a code cell below the selected cell, do one of the following:
In the edit mode, press .
In the command mode, press .
Click
Code Cell Below on the notebook toolbar.
Use the popup between cells to add
code
,Markdown
,SQL
orAI
cells to your notebook:The popup will automatically appear if you hover between two cells in the notebook.
To select a cell, click the gutter next to the cell.
To select several cells:
Click the gutter next to cells while holding for a series of consecutive cells, or for non-consecutive cells.
In the command mode, hold and press the and keys.
You can execute, copy, merge, expand, comment and delete the selected cells.
To rearrange your notebook cells:
Click and hold the drag icon
in the gutter next to the cell.
Drag the cell to the required position and release the mouse button to drop it in the highlighted area.

To copy a cell in the command mode, press , , or click
on the notebook toolbar.
To paste the copied cell below, press , , or click
.
To paste it above the current cell, press with /.
You can also select the required action from the cell's context menu.
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.
Click the border in the gutter to expand or collapse a notebook cell.
Expanded notebook cellCollapsed notebook cellClick the chevron next to the Markdown cell heading to collapse or expand code cells below. The number of collapsed cells will be shown under the heading.
Expanded notebook cellsCollapsed notebook cells
To comment out an active cell, switch to the command mode and press .
To comment out multiple cells, select them in the command mode, then press .
Click
Delete Cell on the notebook toolbar.
Right-click the cell and select Delete Cell from the context menu.
You can assign and view tags for each cell right in the notebook editor:
Right-click the cell.
Select Add Cell Tag from the context menu.
Enter the tag and click Confirm.
To remove the tag, right-click it and select Remove Tag.
You can edit code cells with the help of Python code insights, such as syntax highlighting and code completion.
PyCharm enables code completion for the names of classes, functions, and variables. Start typing the name of the code construct, and the suggestion list appears.
Methods and functionsClass variablesFile pathsPackagesDataFrame columnsnote
The auto-completion of DataFrame columns names is available in runtime. PyCharm will suggest the names for columns only if the cell where the DataFrame is created has already run in the current kernel session.
Intention actions and quick fixes. You can add the missing imports 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.
You can configure Notebooks-aware syntax highlighting according to your preferences and habits.
In the Settings dialog () , go to Editor | Color Scheme | Notebooks.
Select the color scheme, accept the highlighting settings inherited from the defaults or customize them as described in Colors and fonts.
For more information on adjusting colors of specific Notebook elements, refer to Jupyter Notebooks Color Scheme.