subject is explained in https://github.com/jupyter/notebook/issues/6001
import nbformat as nbf
from glob import glob
import uuid
def get_cell_id(id_length=8):
return uuid.uuid4().hex[:id_length]
# your notebook name/keyword
= '04 - data analysis from dataprophet - W34.ipynb'
nb_name = list(filter(lambda x: nb_name in x, glob("./*.ipynb", recursive=True)))
notebooks
# iterate over notebooks
for ipath in sorted(notebooks):
# load notebook
= nbf.read(ipath, nbf.NO_CONVERT)
ntbk
= []
cell_ids for cell in ntbk.cells:
'id'])
cell_ids.append(cell[
# reset cell ids if there are duplicates
if not len(cell_ids) == len(set(cell_ids)):
for cell in ntbk.cells:
'id'] = get_cell_id()
cell[
nbf.write(ntbk, ipath)