How can I reduce the file size of my iPython notebook?

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.

enter image description here
And then save the file.

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.


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.