-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremove.py
More file actions
26 lines (20 loc) · 780 Bytes
/
Copy pathremove.py
File metadata and controls
26 lines (20 loc) · 780 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import nbformat
def delete_markdown_cells(notebook_path):
# Load the notebook
with open(notebook_path, 'r', encoding='utf-8') as f:
nb = nbformat.read(f, as_version=4)
# Iterate over each cell
cells_to_keep = []
for cell in nb['cells']:
# Only keep non-Markdown cells
if cell['cell_type'] != 'markdown':
cells_to_keep.append(cell)
# Replace the notebook's cells with the filtered ones
nb['cells'] = cells_to_keep
# Save the modified notebook
with open(notebook_path, 'w', encoding='utf-8') as f:
nbformat.write(nb, f)
# Specify the path to your Jupyter Notebook file
notebook_path = 'notebook.ipynb'
# Call the function to delete Markdown cells
delete_markdown_cells(notebook_path)