Research Methods for Global Studies II (GLO1221)

Logo

Teaching material for Quantitative Methods track in Semester 1

View the Project on GitHub piratepeel/GlobalStudiesQuantMethodsS1

Tutorial 1
Tutorial 2
Tutorial 3
Tutorial 4
Tutorial 5
Tutorial 6
Tutorial 7
Tutorial 8

Preparing homework submissions
Notes on using Google Colab

Using Google Colab

For the most part, Google Colab works much the same as Jupyter notebooks in Anaconda, aside from some cosmetic differences. An important differences is that you can run the Jupyter notebooks on your computer locally, whereas Google Colab runs the code on a remote machine in the cloud.

Loading files

You can still load files into Colab from a remote source in the same way as you would for Jupyter notebooks (see Loading Data from a Remote Source in Tutorial 4). However, you cannot load files from your computer in the same way because Colab is running on a different machine.

When you need to load data files into Colab, you need to make the file available to the remote machine that is running your code. There are a number of ways to do this:

  1. Upload the file to Colab by selecting the folder icon and then clicking the file upload button. upload file Then you can run the normal code for loading data locally, e.g.,
     import pandas as pd
     data = pd.read_csv('BAGS_IntroSurvey.csv')
    
  2. You can upload the file to your Google Drive and mount the drive so that Colab can access it, e.g.,
     # mount your google drive so colab can access it
     from google.colab import drive
     drive.mount('/content/drive')
        
     # load your data from your google drive
     import pandas as pd
     data = pd.read_csv('/content/drive/MyDrive/data.csv')
    
  3. You can use python to upload the file:
     from google.colab import files
     uploaded = files.upload()
    

    This will produce a Browse... button that allows you to find and upload the file upload files code Then you can run the normal code for loading data locally, e.g.,

     import pandas as pd
     data = pd.read_csv('BAGS_IntroSurvey.csv')