Google Colab: An Online Jupyter Notebook That You Should Definitely Try | by Alan Jones | Towards Data Science

I’ve used Google Colab quite a lot. It used to be my default Jupyter Notebook environment and the starting point for many of my articles on Medium (I also use VSCode these days, too, but that is another story).
Colab is an online Jupyter Notebooks environment from Google. It does everything that a local notebook would do (and more) but it is in the cloud, so no software installation is necessary and it is available from any internet connected computer.
It’s very familiar-looking being similar to the Jupyter environment that you might have installed on you own PC — we’ll look at some of the differences later.
It only runs Python 3 at present (although R and Scala are mentioned as possible future developments) and it comes with many of the most popular Python libraries already installed.
And if you need to install any additional packages, you can do so using pip in a notebook cell.
!pip install a-new-package
And this will remain loaded for the duration of your session.
To use Colab you will need a Google account, otherwise, no set up is required and any notebooks that you create will be stored in the Google Drive associated with your account. You can also put them in a Github repository, if you wish.
Google Colab is offered on a freemium basis. The free subscription tier has limited resources although I think you’d need to be doing some pretty complex stuff to reach the limit. If you need more memory or compute power you can subscribe to a higher tier.
If you have notebooks on your local machine, you can upload them to Colab and you can also download Colab notebooks to store them locally.
Colab notebooks are executed in a virtual machine which will automatically terminate if it has been idle for a while, although if you accidentally close your browser when working you will probably find that when you open it again, the notebook is still running. The maximum time that you can have a virtual machine running for is limited but Google suggest that this can be up to 12 hours.
All this seems to mean that, for all intents and purposes, Colab is free for personal use but if you need to use it for commercial purposes you might need to shell out a few dollars each month.
Data is stored on your Google Drive. Libraries are provided to read and write to Drive and you can, of course load data from the web using the usual Python packages.
Jupyter Notebooks are great for data science and so, so is Colab, but in addition, if you want to run ML code in Tensorflow (included, of course) then Colab provides GPUs in order to run you code better.
As you can see from the images below, the layout is pretty similar to a standard Jupyter Notebook. But Colab has a few differences.
The main difference that you can see is the missing icons in Colab but all of the commands are available from the drop-down menus or from the icon bar that appears above each cell.
There is no Kernel menu in Colab as only there is only one kernel to choose from — restarting the kernel is done from the Runtime menu.
One very useful feature of Colab is the Variables panel where you can see the types and values of each of the current variables.
And more impressive is the way you can view a dataframe as an interactive table. When you display a dataframe from a code cell, as in the cell below...
you will see a pale blue icon that, when clicked, invokes the interactive table.
Not only can you see the data in the table and all the values, you can also filter that data by values in the various columns and sort it by clicking on the column headings.
As I mentioned earlier, Colab used to be my go to Jupyter editor and one of the reasons was that I wanted to be able to run and edit my code from different places on different machines. Colab makes this extremely easy.
Another advantage is that the computing power available to run Colab notebooks in the cloud is vastly superior to that of the often feeble hardware the I was using to edit the notebooks with, meaning that they would run better and faster.
I hope this brief introduction to Google Colab has been useful and that you’ll give it a try.
As ever, thanks for reading. If you would like, you can subscribe to my occasional free newsletter, Technofile which is on Substack — I post about new articles there. Here for example is the post about a bunch of Streamlit articles that I wrote.