Skip to content

Instantly share code, notes, and snippets.

@agounaris
Created April 28, 2017 23:21
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agounaris/5da16c233ce480e75ab95980831f459e to your computer and use it in GitHub Desktop.
Save agounaris/5da16c233ce480e75ab95980831f459e to your computer and use it in GitHub Desktop.
Word count of markdown jupyter notebook cells
import io
from IPython.nbformat import current
with io.open(filepath, 'r', encoding='utf-8') as f:
nb = current.read(f, 'json')
word_count = 0
for cell in nb.worksheets[0].cells:
if cell.cell_type == "markdown":
word_count += len(cell['source'].replace('#', '').lstrip().split(' '))
print(word_count)
@Abhyuday10-beep
Copy link

SOFTWARE ANALYTICS (FINAL ASSESSMENT)-page-001

@MohsinAliJafery
Copy link

MohsinAliJafery commented Nov 30, 2022

It really works after replacing the path with the filename. Thankyou so much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment