0

I have been writing a code at work which to my biggest mistake did not save the python code, not even added checkpoints. It simply got saved in Jupyter. Recently i was testing something and I ended up displaying all the values in my data frame which messed up the memory required to display it. So now when I try to open up the file it simply loads for a while and shows an error error

I tried to download the file from the homepage but it seems to be converted into a JSON file with 955645 lines of code. My python code would barely be of 500 lines.

JSON file code

I tried checking the directory but I am unable to retrieve my original code. Is there any way i can retrieve my original code or convert JSON to python?

Please HELP!

Lesson learnt: Always save your code on Github or create checkpoints. :(

user1884763
  • 53
  • 1
  • 3
  • I don't think this should be closed. There are other solutions besides converting from the json (I assume representing the `.ipynb` file) to a Python file, which is what is linked. Just removing the output from the `.ipynb` file itself should presumably make it open again as an `.ipynb` file if it really is a simple as the OP says. My [answer here to 'Open Jupyter notebook without render images and without popolating dataframes - safe mode loading preventing out of memory state'](https://stackoverflow.com/a/74394583/8508004) details several ways to do that **and is actually what OP seeks.** – Wayne Mar 09 '23 at 19:03
  • What is the extension on the JSON file you show above? Hopefully it is `.ipynb`. Even if it isn't, just change the extension to `.ipynb` because that is what you have in the image you post. Sometimes browsers mistakenly garble the mimetype sutff and save with `.json`, see [here](https://discourse.jupyter.org/t/i-cant-download-my-notebook-as-ipynb-anymore-it-saves-as-json/7043?u=fomightez), and note [the solution after-the-fact is straightforward](https://discourse.jupyter.org/t/i-cant-download-my-notebook-as-ipynb-anymore-it-saves-as-json/7043/2?u=fomightez). As stated clearly in this old... – Wayne Mar 09 '23 at 19:24
  • version of IPython documentation [here](https://ipython.org/ipython-doc/3/notebook/nbformat.html) (see first line of the 'Introduction' section, the Jupyter notebook files are just json files. They conform to a special format the enables `nbformat` and `nbconvert`and similar tech to recognize pertinent features. – Wayne Mar 09 '23 at 19:28
  • Jupyter notebooks are a valid way to save your code, too. If you don't want the output committed in the Jupyter notebook files saved to GitHub, note that [nb-clean](https://github.com/srstevenson/nb-clean) includes a Git filter or pre-commit hook. You can use either to have it automatically strip out the output sections in the notebook file from what get pushed to GitHub. And if you really do want to keep both Jupyter and Python script versions of the code in the notebooks, then check out [Jupytext's paired notebooks](https://github.com/mwouts/jupytext#paired-notebooks). – Wayne Mar 09 '23 at 19:35

0 Answers0