手动清理日志

  • nbconvert
jupyter nbconvert --clear-output \
  --to notebook \
  --output=my_notebook_no_out \
  my_notebook.ipynb

或者

jupyter nbconvert \
    --ClearOutputPreprocessor.enabled=True \
  --to notebook \
  --output=my_notebook_no_out \
  my_notebook.ipynb
  • jq
clean = "jq '.cells[].outputs = [] | .cells[].execution_count = null | .'"

clean = "jq '.cells |= map(if .\"cell_type\" == \"code\" then .outputs = [] | .execution_count = null else . end | .metadata = {}) | .metadata = {}'"