How to use Google Colab
Google Colaboratory, or Google Colab for short, is a free, cloud-based Jupyter Notebook environment. It is like Google Docs but for coding—it doesn’t require you to install anything. It allows you to write and execute Python code through the browser.

It has several advantages:

  • no need to set up anything;
  • you can work on one project together with other people;
  • it has most of the necessary additional extensions for Python (these are called libraries, and we’ll talk about this later).
Why we cannot recommend this tool as the only one:

  • the free version may not work as fast as we wish;
  • in the free version, long-running tasks may unexpectedly terminate;
  • data files take up space in cloud storage (there isn’t much of it there);
  • some data files may not be allowed to be placed in cloud storage;
  • if you don’t use it for a while, everything gets deleted and you have to start over.
However, it’s an excellent tool to get started! Let’s try it.
Starting with Google Colab

  1. Go to colab.research.google.com
  2. Sign in with your Google account
  3. Click “New notebook” to create a new notebook
Files that you create can be seen if you click “File -> Locate in Drive”. Or you can find the Colab Notebooks folder in your cloud storage.
In Colab, a special format for working with scripts is used—a notebook that consists of alternating blocks of code and text. To add code, you need to click the “+ Code” button, as shown in the picture. To add text, click “+ Text”. Text can be a description for the code or addition of various instructions.
To run the code, you need to click the button with the play icon. After execution, its result will be shown under the cell, and you will see a green checkmark if the code executed successfully.
In Colab, individual code cells can be rearranged using the arrow buttons.
And to upload a file, you need to click the button with the folder icon.
Then click the button with the file icon and select on your computer the file that you need to upload for work. Note that all uploaded files will disappear once the you close the session.
The uploaded file should appear in the file explorer panel on the left side of the screen (we have uploaded court_decisions.csv).
Starting coding

You can try creating and running several simple programs. Let’s just add two numbers:
2 + 2
Let’s print a string
print('Hello')
Let’s download a python library. (Libraries are pre-written collections of code that add extra functionality to Python. Think of them as toolkits - instead of writing everything from scratch, you can use libraries that contain ready-made functions for specific tasks like data analysis, creating graphs, or working with files. Below we’ll show how to load the pandas library, which is most commonly used for analyzing tabular data.
import pandas as pd
If library uploaded correctly the cell doesn’t have any output. Now we can open a csv file using pandas library. Let’s open a sample file that comes with any Colab notebook and see the first rows of it with .head() function.
court_decisions = pd.read_csv('/content/court_decisions.csv')
court_decisions.head()
SUBSCRIBE TO OUR NEWSLETTER
Contact US
+1 (202) 9946340
russiaprogram@gwu.edu

INSTITUTE FOR EUROPEAN, RUSSIAN, AND EURASIAN STUDIES

1957 E St., NW, Suite 412,

Washington, DC 20052