Skip to content

Instantly share code, notes, and snippets.

@planetacomputer
Created May 3, 2021 04:47
Show Gist options
  • Save planetacomputer/281458690d0e632e3a2be13448a18b8d to your computer and use it in GitHub Desktop.
Save planetacomputer/281458690d0e632e3a2be13448a18b8d to your computer and use it in GitHub Desktop.
Jupyter - Delete all code cells except markdown text
import nbformat as nbf
ntbk = nbf.read("Exercises_numpy.ipynb", nbf.NO_CONVERT)
cells_to_keep = []
for cell in ntbk.cells:
if cell.cell_type == "markdown":
cells_to_keep.append(cell)
new_ntbk = ntbk
new_ntbk.cells = cells_to_keep
nbf.write(new_ntbk, "new_md_only_notebook.ipynb", version=nbf.NO_CONVERT)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment