Reputation: 136675
I have an IPython notebook which is several megabytes big although the code inside is just about 100 lines. I think it is that huge because I load several images inside.
I would like to add this notebook to a git repository. However, I don't want to upload something that big which can easily be generated again.
Is it possible to save just the code of an IPython notebook to reduce its size?
Upvotes: 24
Views: 33779
Reputation: 1
Yes, you will have big issues with Github, Checkpoints, and Git History.
Clear out the Kernal, save, and then push to github.
Be careful not to save checkpoints that are loaded with images. They also have to be under the 100Mb limit. Clear them out first or else add the checkpoint folder to gitignore.
Upvotes: -1
Reputation: 127
I run into the exact same problem with one of my notebooks, which I solved by changing my df
to df.head(5)
. I did this instead of clearing all outputs as I still wanted to show on GitHub how my code changed data inside the columns in my df.
You also can run !ls -lh
in the last cell of your notebook to check size of your notebook before saving. This will give you an idea if you need to clear outputs/replace df with df.head()/remove images in order to reduce the size and be able to save on the GitHub.
Upvotes: 1
Reputation: 2431
Now you generate a simple script linked to the notebook with jupytext which others can rerun.
If you need to keep the images within (because, for example, you are sharing the notebook with someone who does not want to/can not rerun it) you might want to try to reduce the images.
I found this module ipynbcompress which seems to do exactly this, but so far I could not install it.
Upvotes: 2
Reputation: 2708
You can try following steps since it worked for me:
Select the "Cell" -> then select "All Outputs" -> There you will find "Clear" option select that.
This will reduce the size of your file (From MBs to kbs). It will also reduce the time to load the notebook next time you open it in your browser.
As per my understanding this will clear all the output created after execution of the code. Since Notebook is holding code+images+comments in addition to this its also holding the out put in that file therefore it will increase the size of the notebook.
Upvotes: 37